# Import external assembly and create a new object
[void] [System.reflection.Assembly]::LoadWithPartialName(“Microsoft.BizTalk.ExplorerOM”)
$Catalog = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer
#BizTalk Config
$Catalog.ConnectionString = “SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI” #connectionstring for the BizTalkMgmtDb
$rcvLocation = “” # Define variable for receive location
$BizAppName =“”
$FilterCondition=“DoNotEnable*”;
$resultToWrite =“”
$OutResultLog = ‘D:\ BizTalkPowerShellService\EnableReceiveLocation\logEnableReceiveLocation.txt’
#Function to retrieve the status of the specify receive location
function CheckReceiveLocatonStatusThenEnable(){
$resultToWrite=‘Process has started to enable receive location on date : ‘+(Get-Date).ToString()
Add-Content $OutResultLog $resultToWrite
$resultToWrite=“”
foreach ($receivePort in $catalog.ReceivePorts)
{
try
{
foreach($receiveLoc in $receivePort.ReceiveLocations | Where {($_.Enable -eq $false)-and ($_.Name -notlike $FilterCondition)})
{
try
{
$rcvLocation = $receiveLoc.Name
$BizAppName = $receivePort.Application.Name
if($receiveLoc.Enable -eq $false)
{
#Enable receive location
enableReceiveLocation
#Wait for few seconds
Start-Sleep -s 5
}
}
catch [Exception]
{
$resultToWrite=$resultToWrite+ ‘Getting Exception: ‘+ $_.Exception.Message +‘ to enable receive location: ‘+$rcvLocation+ ‘ in BizTalk Application: ‘+$BizAppName+‘ at datetime: ‘+(Get-Date).ToString()+“`r`n”
Add-Content $OutResultLog $resultToWrite
$resultToWrite=“”
}
}
}
catch [Exception]
{
$resultToWrite=$resultToWrite+ ‘Getting Exception : ‘ +$_.Exception.Message +‘ on receive port loop at datetime: ‘+(Get-Date).ToString()+“`r`n”
Add-Content $OutResultLog $resultToWrite
$resultToWrite=“”
}
}
$resultToWrite=$resultToWrite+ ‘Process end to enabled receive location on datetime: ‘+(Get-Date).ToString() +“`r`n”
Add-Content $OutResultLog $resultToWrite #logged all details in log file
[void]$Catalog.Refresh() # refresh biztalk console
}
#Function to enable the receive location
function enableReceiveLocation(){
$location = get-wmiobject MSBTS_ReceiveLocation -Namespace ‘root\MicrosoftBizTalkServer’ -Filter “name=’${rcvLocation}‘”
[void]$location.Enable()
$resultToWrite=$resultToWrite+ ‘Receive location: ‘+$rcvLocation+ ‘ has enabled in BizTalk Application: ‘+$BizAppName+‘ at datetime :’+(Get-Date).ToString()
Add-Content $OutResultLog $resultToWrite
$resultToWrite=“”
}
#check status of Receive Location
CheckReceiveLocatonStatusThenEnable
Please keep in mind the following instructions: Use the BizTalk Admin Group user to create a Window Task Scheduler. If the BizTalkMgmtDb database is running under a different user, please define the username and password in the ConnectionString.
Additionally, you can refer to another PowerShell script to enable only one receive location. The script is titled “PowerShell Script to Enable a ReceiveLocation“.