Windows Azure BizTalk Service Powershell Cmdlets
Windows Azure BizTalk Service provides a rich set of scripting and automation tools. Chief among them is the Powershell Cmdlets. These cmdlets enable the user to write long running scripts, for eg., get notified via email in case any of the FTP sources are down, clear the tracking DB at regular intervals, etc.
While a start, we will be constantly enhancing the capabilities of these cmdlets including their ease of use.
Installation
- Install the Windows Azure BizTalk Services SDK. See Installing the Windows Azure BizTalk Services SDK - June 2013 Preview for instructions.
- Open a PowerShell window with administrator privileges.
- Run import-module to import the BizTalk Services module to the current session.
Import-module “C:\Program Files\Windows Azure BizTalk Services SDK\Microsoft.BizTalk.Services.Powershell.dll
NOTE: You need powershell 3.0 installed to use the Windows Azure BizTalk Services Powershell cmdlets.
Cmdlets
Following are the cmdlets that are made available as part of the BizTalk SDK.
Cmdlet Name |
Description |
Get-AzureBizTalkBridge
|
Lists bridges deployed |
Remove-AzureBizTalkBridge
|
Deletes bridge deployed |
Add-AzureBizTalkArtifactXmlSchema
|
Adds an XML schema artifact |
Add-AzureBizTalkArtifactTransform
|
Adds a transform artifact |
Add-AzureBizTalkArtifactAssembly
|
Adds an assembly artifact
|
Add-AzureBizTalkArtifactCertificate
|
Adds a certificate artifact
|
Get-AzureBizTalkArtifact
|
List artifacts deployed
|
Save-AzureBizTalkArtifact
|
Save artifacts locally
|
Remove-AzureBizTalkArtifact
|
Removes artifact deployed
|
Start-AzureBizTalkBridgeSource
|
Starts Bridge source
|
Stop-AzureBizTalkBridgeSource
|
Stops Bridge source
|
Get-AzureBizTalkBridgeSource
|
Get source status
|
Restart-AzureBizTalkService |
Restarts BizTalk Service |
Clear-AzureBizTalkTrackingStore
|
Clear tracking store |
For a detailed description/usage of the above powershell cmdlets, please refer to our documentation here.
Scenario
Let’s look at how these powershell cmdlets may be used to address some complex user scenarios.
$a = ‘myAcsNamespace’
$b=’myIssuerName’
$c=’myIssuerKey’
$d=’ https://myDeploymentUri.windows.biztalk.net/default/’
Remove all bridges under Samples
To remove all bridges under a folder say Samples, you would have to get all the bridges under samples, which can be done using Get-AzureBizTalkBridge, and then pipe the list of bridges you get to Remove-AzureBizTalkBridge which removes each of those bridges.
Get-AzureBizTalkBridge –AcsNamespace $a –IssuerName $b –IssuerKey $c –DeploymentUri $d –BridgePath Samples -Recurse | %{Remove-AzureBizTalkBridge –AcsNamespace $a –IssuerName $b -IssuerKey $c –DeploymentUri $d -BridgePath $_.Path -NoPrompt}
Start all sources that are stopped for bridges under Samples
Here, first you have to get all bridges under Samples folder. This can be done using the Get-AzureBizTalkBridge cmdlet. Once you get this list, you can pipe the output to Get-AzureBizTalkBridgeSource which will return you all the sources for each bridge. You filter that list by only getting the ones that are Stopped. Once you have this list of sources that are stopped, you can pass it along to Start-AzureBizTalkBridgeSource to start them all.
Get-AzureBizTalkBridge –AcsNamespace $a –IssuerName $b –IssuerKey $c –DeploymentUri $d -BridgePath Samples –Recurse | %{Get-AzureBizTalkBridgeSource –AcsNamespace $a –IssuerName $b –IssuerKey $c –DeploymentUri $d -BridgePath $_.Path} | where {$_.Status –ieq ‘Stopped’} | %{Start-AzureBizTalkBridgeSource –AcsNamespace $a –IssuerName $b –IssuerKey $c –DeploymentUri $d –BridgePath $_.BridgePath}
Download all artifacts under Samples
To download all the artifacts under Samples, you use the Get-AzureBizTalkArtifact to get all artifacts and pipe them to Save-AzureBizTalkArtifact which saves the artifacts locally.
Get-AzureBizTalkArtifact –AcsNamespace $a –IssuerName $b –IssuerKey $c –DeploymentUri $d -ArtifactPath 'Artifact1' –Recurse | %{ Save-AzureBizTalkArtifact –AcsNamespace $a –IssuerName $b –IssuerKey $c DeploymentUri $d -ArtifactPath $_.ArtifactPath –SavePath ([string]::Format(‘{0}{1}’, ‘E:\TestFolder\’, $_.ArtifactName)) -Overwrite }
Remove all XML schemas
To remove all XML schemas, you first Get-AzureBizTalkArtifact for all artifacts and filter them down to those of type XMLSchemaDefinition. You then pipe this list to Remove-AzureBizTalkArtifact and remove each one of them.
Get-AzureBizTalkArtifact –AcsNamespace $a –IssuerName $b –IssuerKey $c –DeploymentUri $d –Recurse | where { $_.ArtifactType.ToString() –eq ‘XmlSchemaDefinition’} | %{ Remove-AzureBizTalkArtifact –AcsNamespace $a IssuerName $b –IssuerKey $c –DeploymentUri $d –ArtifactPath $_.ArtifactPath -NoPrompt }