BTSReset with PowerShell
In a previous post I mentioned that you could work with the WMI interfaces in BizTalk Server easier in PowerShell than you could with C#, and in a more interactive fashion. Here's something else I cooked while playing with the PowerShell RC1: A PowerShell version of my BTSReset tool!
Update: Fixed code so that it works with PowerShell V1 RTM.
#
# declare two switch parameters: -start and -stop
#
param([switch] $start, [switch] $stop)
#
# get list of application hosts
#
function get-apphosts
{
get-wmiobject MSBTS_HostInstance `
-namespace 'root\MicrosoftBizTalkServer' `
-filter HostType=1
}
#
# stop the given host
#
function stop-host($apphost)
{
$hostname = $apphost.HostName
if ( $apphost.ServiceState -ne 1 )
{
"Stopping Host $hostname ..."
[void]$apphost.Stop()
}
}
#
# start the given host
#
function start-host($apphost)
{
$hostname = $apphost.HostName
if ( $apphost.ServiceState -eq 1 )
{
"Starting Host $hostname ..."
[void]$apphost.Start()
}
}
#
# main script
#
if ( !($stop) -and !($start) )
{
$stop = $true
$start = $true
}
if ( $stop )
{
get-apphosts | %{ stop-host($_) }
}
if ( $start )
{
get-apphosts | %{ start-host($_) }
}
Here's a few examples of running the tool from the PowerShell prompt:
PS E:\temp> .\bts-reset.ps1
Stopping Host BizTalkServerApplication ...
Starting Host BizTalkServerApplication ...
PS E:\temp> .\bts-reset.ps1 -stop
Stopping Host BizTalkServerApplication ...
PS E:\temp> .\bts-reset.ps1 -stop
PS E:\temp> .\bts-reset.ps1 -start
Starting Host BizTalkServerApplication ...






Nice job — looks like you managed to squeeze out quite a few lines of code while you were at it
Very nice.
PSMDTAG:FAQ: How do I start/stop BizTalk Server Applications?
PSMDTAG:TYPE:WMI: MSBTS_HostInstance
Jeffrey Snover [MSFT]
Windows PowerShell/Aspen Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx