From f49c379106c90e78aa81c18003b319a05fcccdaf Mon Sep 17 00:00:00 2001 From: Christophe CREMON Date: Fri, 6 Jul 2012 11:33:38 +0200 Subject: [PATCH] PowerBizTalk --- PowerBizTalk/PowerBizTalk.Format.ps1xml | 216 +++++++++++ PowerBizTalk/PowerBizTalk.Type.ps1xml | 184 +++++++++ PowerBizTalk/PowerBizTalk.psd1 | Bin 0 -> 5238 bytes PowerBizTalk/PowerBizTalk.psm1 | 481 ++++++++++++++++++++++++ 4 files changed, 881 insertions(+) create mode 100644 PowerBizTalk/PowerBizTalk.Format.ps1xml create mode 100644 PowerBizTalk/PowerBizTalk.Type.ps1xml create mode 100644 PowerBizTalk/PowerBizTalk.psd1 create mode 100644 PowerBizTalk/PowerBizTalk.psm1 diff --git a/PowerBizTalk/PowerBizTalk.Format.ps1xml b/PowerBizTalk/PowerBizTalk.Format.ps1xml new file mode 100644 index 0000000..30690a2 --- /dev/null +++ b/PowerBizTalk/PowerBizTalk.Format.ps1xml @@ -0,0 +1,216 @@ + + + + + + BizTalk-Applications + + Microsoft.BizTalk.ExplorerOM.Application + + + + + + + + + + + + + + + Item + + + State + + + + + + + + + BizTalk-Orchestrations + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_Orchestration + + + + + + + + + + + + + + + Item + + + State + + + + + + + + + BizTalk-SendPortGroups + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_SendPortGroup + + + + + + + + + + + + + + + Item + + + State + + + + + + + + + BizTalk-SendPorts + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_SendPort + + + + + + + + + + + + + + + Item + + + State + + + + + + + + + BizTalk-ReceiveLocations + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_ReceiveLocation + + + + + + + + + + + + + + + Item + + + State + + + + + + + + + BizTalk-HostInstances + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_HostInstance + + + + + + + + + + + + + + + Item + + + State + + + + + + + + + BizTalk-ServiceInstances + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_ServiceInstance + + + + + + + + + + + + + + + + + + Item + + + State + + + InstanceID + + + + + + + + + + \ No newline at end of file diff --git a/PowerBizTalk/PowerBizTalk.Type.ps1xml b/PowerBizTalk/PowerBizTalk.Type.ps1xml new file mode 100644 index 0000000..64148e5 --- /dev/null +++ b/PowerBizTalk/PowerBizTalk.Type.ps1xml @@ -0,0 +1,184 @@ + + + + Microsoft.BizTalk.ExplorerOM.Application + + + Item + + return $this.Name + + + + State + + return $this.Status + + + + + + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_Orchestration + + + Item + + return $this.Name + + + + State + + switch ($this.OrchestrationStatus) + { + '1' { $State = "Unbound" } + '2' { $State = "Bound" } + '3' { $State = "Stopped" } + '4' { $State = "Started" } + default { $State = "N/A" } + } + return $State + + + + + + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_SendPortGroup + + + Item + + return $this.Name + + + + State + + switch ($this.Status) + { + '1' { $State = "Bound" } + '2' { $State = "Stopped" } + '3' { $State = "Started" } + default { $State = "N/A" } + } + return $State + + + + + + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_SendPort + + + Item + + return $this.Name + + + + State + + switch ($this.Status) + { + '1' { $State = "Bound" } + '2' { $State = "Stopped" } + '3' { $State = "Started" } + default { $State = "N/A" } + } + return $State + + + + + + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_ReceiveLocation + + + Item + + return $this.Name + + + + State + + switch ($this.IsDisabled) + { + 'False' { $State = "Enabled" } + 'True' { $State = "Disabled" } + default { $State = "N/A" } + } + return $State + + + + + + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_HostInstance + + + Item + + return $this.Name + + + + State + + switch ($this.ServiceState) + { + '1' { $State = "Stopped" } + '2' { $State = "Start pending" } + '3' { $State = "Stop pending" } + '4' { $State = "Running" } + '8' { $State = "Unknown" } + default { $State = "N/A" } + } + return $State + + + + + + + System.Management.ManagementObject#root\MicrosoftBizTalkServer\MSBTS_ServiceInstance + + + Item + + if ( $this.AssemblyName ) + { + return $this.AssemblyName+'.'+$this.ServiceName + } + else + { + return $this.ServiceName + } + + + + State + + switch ($this.ServiceStatus) + { + '1' { $State = "Ready to run" } + '2' { $State = "Active" } + '4' { $State = "Suspended (resumable)" } + '8' { $State = "Dehydrated" } + '16' { $State = "Completed with discarded messages" } + '32' { $State = "Suspended (not resumable)" } + '64' { $State = "In breakpoint" } + default { $State = "N/A" } + } + return $State + + + + + + \ No newline at end of file diff --git a/PowerBizTalk/PowerBizTalk.psd1 b/PowerBizTalk/PowerBizTalk.psd1 new file mode 100644 index 0000000000000000000000000000000000000000..722d8f9fe5a5db9540e190145d305793132c46dc GIT binary patch literal 5238 zcmcJTYi}Dx6o$`dB>sb?erO8Rb&8=B38^L_rBWNJCM|q*d0^?78E!?&gTR%tD$pV?pG zO|;-dI&;}L4gQz}{n20Un=_4OvOkwy_^|A$p~l>|U3qk-v7X)(zPQxWT=q4>??^MM zQ2igdQ)+GWnC*banhqBv8*_{uT7`Q6WPK#-B)RYQ6vqdW@mMjUZgI`#Zv7%x~NR#TB5_;469yeBXCIDAR%6RW9YUr4%VeB{VY`Myr4d#YgP z6UD;0bCv6f0MTja7psXX)_&C8LRYWKo}P#t`0>VZ_o4&BZ>}r#nEyPOg0gi|mDX zwNzzahUj5sSMTdErhY{ioG=ldiB{nKGFzqo{WZ)c)7_3b`3*_Pl%L2YCPWs-8HKxT z{9Y%up7~N+idwo2Y8c1&K7Wrs82 zrTmtQ18MsJ>F zzIGcc($2;AC3>fx_y|56=x#2YV1PZ2g9QWoN>9Jpcj6K5IzrvoeLFn8&@=b!4mZbM zMbue~r@l^#z6b^_m=)&ox}}$(qhW`}=GY6vM9#FVV$ONs;xokwzJ;$~Oc*x{k@9_% z9fN%YhV}Jj*+@MPBXzwSy~!I%E;C=blZ*Z2GkO0((hGNF4Lcz{BD)v+;wF39Rl16k z_j$XhRNbeVEBjPa)qSOCfRUWZ?HBECDFddxf9&P4c~4ycJ@tObxgz3ZvhOTZ z7ZK+-#om@nA(P$u zBH#Z%C!_B5csHGJ;_4U|N1Dd-D8!mmuJ@vTHcR7qmll@w-_FXigiV&N)^n93==-po zP6&?j8fCwT{|7Ldb}Qvk`g<~k^DMdI>pkDg+N-$-|F926t>xM1q=KuNc_c2)!rtKh zGc(<)L8xPARr+kWl75k@tDaoZUX=w(=YuH6dE|=~MmUhcbJI^R>HjXE;w0Qtujc&@y?yGoUZ2bj{Cs>AM)q8 U5ACjwQv`?C`n`Gz_Wj%b14VXg(*OVf literal 0 HcmV?d00001 diff --git a/PowerBizTalk/PowerBizTalk.psm1 b/PowerBizTalk/PowerBizTalk.psm1 new file mode 100644 index 0000000..f83fe32 --- /dev/null +++ b/PowerBizTalk/PowerBizTalk.psm1 @@ -0,0 +1,481 @@ +# BizTalk Administration PowerShell Module +# http://powershell.codeplex.com + +# BizTalk Generic WMI Call +Function Invoke-BizTalkGenericWmiCall +{ + param ( [string] $Artifact, + [string] $ArtifactChild, + [string] $Action ) + + if ( $Artifact -eq "HostInstance" ) + { + $WMIQuery = Get-WmiObject -Class "MSBTS_$Artifact" -Namespace "root\MicrosoftBizTalkServer" -Filter "HostName='$ArtifactChild'" + } + else + { + $WMIQuery = Get-WmiObject -Class "MSBTS_$Artifact" -Namespace "root\MicrosoftBizTalkServer" -Filter "Name='$ArtifactChild'" + } + + if ( $WMIQuery -eq $null ) + { + Write-Output "ERROR : Unknown $Artifact [ $ArtifactChild ] !" + } + else + { + [string] $ObjectState = $WMIQuery.State + + switch ( $Artifact ) + { + 'Orchestration' { $StopState = "Stopped|Bound" ; $StartState = "Started" ; } + 'SendPortGroup' { $StopState = "Stopped|Bound" ; $StartState = "Started" ; } + 'SendPort' { $StopState = "Stopped|Bound" ; $StartState = "Started" ; } + 'ReceiveLocation' { $StopState = "Disabled" ; $StartState = "Enabled" ; } + 'HostInstance' { $StopState = "Stopped" ; $StartState = "Running" ; } + } + + switch ( $Action ) + { + 'Start' { $ExpectedState = $StopState ; $WMICommand = '$WMIQuery.Start()' ; } + 'Stop' { $ExpectedState = $StartState ; $WMICommand = '$WMIQuery.Stop()' ; } + 'Enable' { $ExpectedState = $StopState ; $WMICommand = '$WMIQuery.Enable()' ; } + 'Disable' { $ExpectedState = $StartState ; $WMICommand = '$WMIQuery.Disable()' ; } + 'Enlist' { $ExpectedState = "Bound" ; $WMICommand = '$WMIQuery.Enlist()' ; } + 'Unenlist' { $ExpectedState = "$StopState|$StartState" ; $WMICommand = '$WMIQuery.Unenlist()' ; } + } + + if ( $ObjectState -match $ExpectedState ) + { + $WMICommit = Invoke-Expression -Command $WMICommand + + if ( ( $WMICommit ) -and ( $? -eq $true ) ) + { + Write-Output "SUCCESS : $Action of $Artifact [ $ArtifactChild ]" + } + else + { + Write-Output "ERROR : Unable to $Action $Artifact [ $ArtifactChild ] !" + } + } + else + { + Write-Output "$Artifact [ $ArtifactChild ] is already $WMIQueryState" + } + } +} + +# BizTalk Catalog Explorer Assembly +Function Invoke-BizTalkEOM +{ + $BizTalkConnectionString = "SERVER=.;DATABASE=BizTalkMgmtDb;Integrated Security=SSPI" + if ( ( Test-Path "HKLM:SOFTWARE\Microsoft\Biztalk Server\3.0\Administration" ) -eq $true ) + { + $BizTalkMgmtDBServer = ( Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Biztalk Server\3.0\Administration" ).MgmtDBServer + $BizTalkMgmtDBName = ( Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Biztalk Server\3.0\Administration" ).MgmtDBName + $BizTalkConnectionString = "SERVER=$BizTalkMgmtDBServer;DATABASE=$BizTalkMgmtDBName;Integrated Security=SSPI" + } + $BizTalkCatalogExplorer = New-Object Microsoft.BizTalk.ExplorerOM.BtsCatalogExplorer + $BizTalkCatalogExplorer.ConnectionString = $BizTalkConnectionString + return $BizTalkCatalogExplorer +} + +# Applications +Function Get-Application +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [string] $Name ) + + process + { + $BizTalkCatalogExplorer = Invoke-BizTalkEOM + $Application = $BizTalkCatalogExplorer.Applications | Where-Object { $_.Item -match "$Name" } + $Application + } +} +Function Start-Application +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + $BizTalkCatalogExplorer = Invoke-BizTalkEOM + $BizTalkApplication = $BizTalkCatalogExplorer.Applications[$Name] + if ( $BizTalkApplication.State -ne "Started" ) + { + $BizTalkApplication.Start([Microsoft.BizTalk.ExplorerOM.ApplicationStartOption] "StartAll") + $BizTalkCatalogExplorer.SaveChanges() + if ( ( $BizTalkApplication ) -and ( $? -eq $true ) ) + { + Write-Output "SUCCESS : Start of Application [ $Name ]" + } + else + { + Write-Output "ERROR : Unable to Start Application [ $Name ] !" + } + } + else + { + Write-Output "Application [ $Name ] is already Started" + } + } +} +Function Stop-Application +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + $BizTalkCatalogExplorer = Invoke-BizTalkEOM + $BizTalkApplication = $BizTalkCatalogExplorer.Applications[$Name] + if ( $BizTalkApplication.State -ne "Stopped" ) + { + $BizTalkApplication.Stop([Microsoft.BizTalk.ExplorerOM.ApplicationStopOption] ("DisableAllReceiveLocations","UnenlistAllOrchestrations","UnenlistAllSendPortGroups","UnenlistAllSendPorts","UndeployAllPolicies")) + $BizTalkCatalogExplorer.SaveChanges() + if ( ( $BizTalkApplication ) -and ( $? -eq $true ) ) + { + Write-Output "SUCCESS : Stop of Application [ $Name ]" + } + else + { + Write-Output "ERROR : Unable to Stop Application [ $Name ] !" + } + } + else + { + Write-Output "Application [ $Name ] is already Stopped" + } + } +} +# + +# Orchestrations +Function Get-Orchestration +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [string] $Name ) + + process + { + Get-WmiObject -Class "MSBTS_Orchestration" -Namespace 'root\MicrosoftBizTalkServer' | Where-Object { $_.Item -match "$Name" } + } +} +Function Start-Orchestration +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Start' -Artifact 'Orchestration' -ArtifactChild $Name + } +} +Function Stop-Orchestration +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Stop' -Artifact 'Orchestration' -ArtifactChild $Name + } +} +Function Register-Orchestration +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Enlist' -Artifact 'Orchestration' -ArtifactChild $Name + } +} +Function Unregister-Orchestration +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Unenlist' -Artifact 'Orchestration' -ArtifactChild $Name + } +} +# + +# Send Port Groups +Function Get-SendPortGroup +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [string] $Name ) + + process + { + Get-WmiObject -Class "MSBTS_SendPortGroup" -Namespace 'root\MicrosoftBizTalkServer' | Where-Object { $_.Item -match "$Name" } + } +} +Function Start-SendPortGroup +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Start' -Artifact 'SendPortGroup' -ArtifactChild $Name + } +} +Function Stop-SendPortGroup +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Stop' -Artifact 'SendPortGroup' -ArtifactChild $Name + } +} +Function Register-SendPortGroup +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Enlist' -Artifact 'SendPortGroup' -ArtifactChild $Name + } +} +Function Unregister-SendPortGroup +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Unenlist' -Artifact 'SendPortGroup' -ArtifactChild $Name + } +} +# + +# Send Ports +Function Get-SendPort +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [string] $Name ) + + process + { + Get-WmiObject -Class "MSBTS_SendPort" -Namespace 'root\MicrosoftBizTalkServer' | Where-Object { $_.Item -match "$Name" } + } +} +Function Start-SendPort +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Start' -Artifact 'SendPort' -ArtifactChild $Name + } +} +Function Stop-SendPort +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Stop' -Artifact 'SendPort' -ArtifactChild $Name + } +} +Function Register-SendPort +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Enlist' -Artifact 'SendPort' -ArtifactChild $Name + } +} +Function Unregister-SendPort +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Unenlist' -Artifact 'SendPort' -ArtifactChild $Name + } +} +# + +# Receive Locations +Function Get-ReceiveLocation +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [string] $Name ) + + process + { + Get-WmiObject -Class "MSBTS_ReceiveLocation" -Namespace 'root\MicrosoftBizTalkServer' | Where-Object { $_.Item -match "$Name" } + } +} +Function Enable-ReceiveLocation +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Enable' -Artifact 'ReceiveLocation' -ArtifactChild $Name + } +} +Function Disable-ReceiveLocation +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Disable' -Artifact 'ReceiveLocation' -ArtifactChild $Name + } +} +# + +# Host Instances +Function Get-HostInstance +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [string] $Name ) + + process + { + Get-WmiObject -Class "MSBTS_HostInstance" -Namespace 'root\MicrosoftBizTalkServer' -Filter "HostType='1'" | Where-Object { $_.Item -match "$Name" } + } +} +Function Start-HostInstance +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Start' -Artifact 'HostInstance' -ArtifactChild $Name + } +} +Function Stop-HostInstance +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + [string] $Name ) + + process + { + Invoke-BizTalkGenericWmiCall -Action 'Stop' -Artifact 'HostInstance' -ArtifactChild $Name + } +} +# + +# Service Instances +Function Get-ServiceInstance +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [string] $Name ) + + process + { + Get-WmiObject -Class "MSBTS_ServiceInstance" -Namespace 'root\MicrosoftBizTalkServer' | Where-Object { $_.Item -match "$Name" -and $_.Item -ne "" } + } +} +Function Remove-ServiceInstance +{ + [CmdletBinding()] + param ( + [ValidateNotNullOrEmpty()] + [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] + $InstanceID ) + + process + { + $WMIQuery = Get-WmiObject -Class "MSBTS_ServiceInstance" -Namespace 'root\MicrosoftBizTalkServer' -Filter "InstanceID='$InstanceID'" + $WMICommit = $WMIQuery.Terminate() + if ( ( $WMICommit ) -and ( $? -eq $true ) ) + { + Write-Output "SUCCESS : Remove of ServiceInstance [ $InstanceID ]" + } + else + { + Write-Output "ERROR : Unable to Remove ServiceInstance [ $InstanceID ] !" + } + } +} +# + +Export-ModuleMember -Function Get-*, Start-*, Stop-*, Enable-*, Disable-*, Register-*, Unregister-*, Remove-* \ No newline at end of file