PowerShell Script to Start Only Specified Host instances and Stop remaining Host Instances in BizTalk server


Hi All,

Some of the times, we are in a situation to start only specified host instances in your biztalk group and stop the remaining . in that case, you could use this script to achieve that.

<#

.SYNOPSIS

<This is the Biztalk Server product related Script, you could use this in the

biztalk server Environment for starting only specified hosts and stop another Host Instances

>

.DESCRIPTION

<Used to Start the specified Host Instances on your BizTalk environment and stop the remaining Hosts >

.EXAMPLE

<Open the script in power Shell ISE with Run as Admin permission in the Any one of the BizTalk Web server and run it>

#>

[ARRAY]$hostInstanceObj = get-wmiobject MSBTS_HostInstance -namespace ‘root\MicrosoftBizTalkServer’

[ARRAY]$HostInstanceObj1 = "BizTalkServerApplication","TrackingHost"

$StophostInstances = $hostInstanceObj | ?{$HostInstanceObj1 -notcontains $_.hostname}

$starthostInstances = $hostInstanceObj | ?{$HostInstanceObj1 -contains $_.hostname}

$StophostInstancesFinal = $StophostInstances|?{$_.HostType -eq ‘1’}

foreach ( $hostInstance in $StophostInstancesFinal)

{

if ( $hostInstance.GetState().state -eq ‘4’)

{

Write-Output " stopping the Host name $($hostInstance.hostname) on Server $($hostInstance.RunningServer)"

$hostInstance.InvokeMethod("Stop",$null)

}

}

foreach ( $stInstance in $starthostInstances)

{

if ( $stInstance.GetState().state -eq ‘1’)

{

Write-Output " Starting the Host name $($stInstance.hostname) on Server $($stInstance.RunningServer)"

$stInstance.InvokeMethod("Start",$null)

}

}

Disclaimer : Please test in Lower environments before using this production . it stop the other host instances that you would not mention.

Regards,

Chaitanya

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: