PowerShell script to enable all BizTalk Receive Location except filter condition i.e. start receive location name with "DoNotEnable"
Hello everyone today I am going to share a PowerShell script that enable all receive(check receive location status before enable it) but most important that I do not enable few receive location so I rename it with starting word as "DoNotEnable". You can rename in your choice but keep simple for better standing.
Before execute following script Please do following task-
a. Set Server name in ConnectionString
b. Set ($FilterCondition) in my case it "DoNotEnable"
c. Set path value of $OutResultLog for log text file
c. Set path value of $OutResultLog for log text file
# 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
Note: Use BizTalk Admin Group user to create Window Task Scheduler and If BizTalkMgmtDb database run under different user then please define Username and possword it in ConnectionString.
You can also see another PS Script to enable only one receive location :PowerShell Script to Enable a ReceiveLocation
Nice blog .Very useful for beginners .Keep updating Biztalk online training Bangalore
ReplyDeleteHi this is a great initiative. Thanks for the good work. Is it possible to get the receive location status using a powershell script?
ReplyDeleteYes, I have already used in my above post. see at this line- if($receiveLoc.Enable -eq $false)
Deletewhat should the $rcvLocation = "" # Define variable for receive location, be ?
ReplyDeleteif this enables all then you shouldnt need to set a specific receivelocation ?
Regards
No It is not possible to enable all receive location in one go, The process start by one by one to enable receive location and $rcvLocation (Variable) I get disable receive location that we ready to enable i.e. in loop.
Delete