# ============================================================================================== # # Microsoft PowerShell Source File -- Created with SAPIEN Technologies PrimalScript 4.1 # # NAME: SOA402_Demos # # AUTHOR: Matt Milner , M3 Technology Partners Inc / Pluralsight LLC # DATE : 6/4/2008 # # COMMENT: # For demonstration purposes only, no rights, guarantees or anything else implied # ============================================================================================== [System.Reflection.Assembly]::LoadFrom("C:\Program Files\Microsoft BizTalk Server 2006\Developer Tools\Microsoft.BizTalk.ExplorerOM.dll") function Get-ScriptDirectory { $Invocation = (Get-Variable MyInvocation -Scope 1).Value Split-Path $Invocation.MyCommand.Path } function Get-BTSConnectionString { $group = Get-WmiObject MSBTS_GroupSetting -n root\MicrosoftBizTalkServer $dbName = $group.MgmtDBName $server = $group.MgmtDBServerName [System.String]::Concat("server=", $server, ";database=", $dbName, ";Integrated Security=SSPI") } function StopBTSApplication { param([string]$appName) $exp = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer $exp.ConnectionString = Get-BTSConnectionString $app = $exp.Applications[$appName] if($app -eq $null) { Write-Host "Application " $appName " not found" -fore Red } else { if($app.Status -ne 2) { #full stop of application $null = $app.Stop(63) $null = $exp.SaveChanges() Write-Host "Stopped application: " $appName } } } function EnableReceiveLocation{ param([string]$locationName) $rec = get-wmiobject MSBTS_ReceiveLocation -n root\MicrosoftBizTalkServer -filter "Name='$locationName'" if($rec -ne $null) { if($rec.IsDisabled -eq $true) { $null = $rec.Enable() Write-Host "Enabled receive location: " + $locationName -fore Green } else { Write-Host "Receive location " + $locationName + " is already enabled." -fore Yellow } } else { Write-Host "Receive location not found" -fore Red } } function DisableReceiveLocation{ param([string]$locationName) $rec = get-wmiobject MSBTS_ReceiveLocation -n root\MicrosoftBizTalkServer -filter "Name='$locationName'" if($rec -ne $null) { if($rec.IsDisabled -eq $false) { $null = $rec.Disable() Write-Host "Disabled receive location: " + $locationName -fore Green } else { Write-Host "Receive location " + $locationName + " is already disabled." -fore Yellow } } else { Write-Host "Receive location not found" -fore Red } } function StartSendPort{ param([string]$portName) $sp = Get-WmiObject MSBTS_SendPort -n root\MicrosoftBizTalkServer -filter "Name='$portName'" if($sp -ne $null) { if($sp.Status -eq 1 -or $sp.Status -eq 2) { if($sp.Status -eq 1) { $null = $sp.Enlist() } $null = $sp.Start() Write-Host "Started send port: " + $portName -fore Green } else { Write-Host "Send port " + $portName + " is already started." -fore Yellow } } else { Write-Host "Send port not found" -fore Red } } function UnenlistSendPort{ param([string]$portName) $sp = Get-WmiObject MSBTS_SendPort -n root\MicrosoftBizTalkServer -filter "Name='$portName'" if($sp -ne $null) { if($sp.Status -eq 3 -or $sp.Status -eq 2) { if($sp.Status -eq 3) { $null = $sp.Stop() } $null = $sp.Unenlist() Write-Host "Unenlisted send port: " + $portName -fore Green } else { Write-Host "Send port " + $portName + " is already unenlisted." -fore Yellow } } else { Write-Host "Send port not found" -fore Red } } function StartOrchestration{ param([string]$orchName) $orch = Get-WmiObject MSBTS_Orchestration -n root\MicrosoftBizTalkServer -filter "Name='$orchName'" if($orch -ne $null) { if($orch.OrchestrationStatus -eq 2 -or $orch.OrchestrationStatus -eq 3) { if($orch.OrchestrationStatus -eq 2) { $null = $orch.Enlist() } $null = $orch.Start() Write-Host "Started orchestration: " + $orchName -fore Green } else { Write-Host "Orchestration " $orchName " is already started." -fore Yellow } } else { Write-Host "Orchestration not found" -fore Red } } function UnenlistOrchestration{ param([string]$orchName) $orch = Get-WmiObject MSBTS_Orchestration -n root\MicrosoftBizTalkServer -filter "Name='$orchName'" if($orch -ne $null) { if($orch.OrchestrationStatus -eq 3 -or $orch.OrchestrationStatus -eq 4) { if($orch.OrchestrationStatus -eq 4) { $null = $orch.Stop() } $null = $orch.Unenlist() Write-Host "Unenlisted orchestration: " + $orchName -fore Green } else { Write-Host "Orchestration " $orchName " is already unenlisted." -fore Yellow } } else { Write-Host "Orchestration not found" -fore Red } }