« Administering BizTalk with PowerShell: P... | Main | BTS Suspended Messaging Instances with P... »
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.ps1Stopping Host BizTalkServerApplication ...Starting Host BizTalkServerApplication ...
PS E:\temp> .\bts-reset.ps1 -stopStopping Host BizTalkServerApplication ...
PS E:\temp> .\bts-reset.ps1 -stop
PS E:\temp> .\bts-reset.ps1 -startStarting Host BizTalkServerApplication ...
Tomas Restrepo is a software developer located in Colombia, South America. His interests include .NET, Connected Systems, PowerShell and lately dynamic programming languages. More...
email: tomas@winterdom.com msn: tomasr@passport.com
Copyright © 2002-2008, Tomas Restrepo.
Powered by: newtelligence dasBlog 2.2.8279.16125