Orchestration Action Module

Microsoft.BizTalk.Server.2016.OrchestrationAction.Task (WriteActionModuleType)

This module is used for performing operations on an orchestration.

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsMicrosoft.BizTalk.ProbeAccount
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
Script WriteAction Microsoft.Windows.ScriptWriteAction Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsThis is the timeout (in seconds) after which execution of the script associated with the module is terminated if not yet completed.

Source Code:

<WriteActionModuleType ID="Microsoft.BizTalk.Server.2016.OrchestrationAction.Task" Accessibility="Public" RunAs="Microsoft.BizTalk.ProbeAccount" Batching="false">
<Configuration>
<xsd:element name="TargetComputer" type="xsd:string"/>
<xsd:element name="OrchestrationName" type="xsd:string"/>
<xsd:element name="TaskOption" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
<ScriptName>Microsoft.BizTalk.Server.2016.OrchestrationAction.vbs</ScriptName>
<Arguments>$Config/TargetComputer$ "$Config/OrchestrationName$" $Config/TaskOption$</Arguments>
<ScriptBody><Script>
'Copyright (c) Microsoft Corporation. All rights reserved.
'*************************************************************************
' $ScriptName: "Start/Stop Orchestration" $
'
' Purpose - This script Start/Stop a Orchestration.
'
' Parameters
' "TargetComputer" = the computer that we target this task
' "OrchestrationName" = the name of the Orchestration
' "Option" = this is the task option (Start/Stop/Enlist/UnEnlist)
'
' $File: Microsoft.BizTalk.Server.2016.OrchestrationAction.vbs $
'
'*************************************************************************

Option Explicit

Dim oArgs
Dim strQuery, strNamespace
Dim strOrchestrationName, strTargetComputer, strOption

Const EVENT_SOURCE = "Task Start/Stop Orchestration"

'Event Type Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4

Const HKEY_CLASSES_ROOT = &amp;H80000000
Const HKEY_CURRENT_USER = &amp;H80000001
Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const HKEY_USERS = &amp;H80000003
Const HKEY_CURRENT_CONFIG = &amp;H80000005

Set oArgs = WScript.Arguments
if oArgs.Count &lt; 3 Then
WScript.Echo "Fail to Receive all Parameters. Please Check."
WScript.Echo "Parameters Count:" &amp; CStr(oArgs.Count)
If oArgs.Count &gt; 0 Then
WScript.Echo "Parameters TargetComputer:" &amp; oArgs(0)
else
WScript.Echo "Parameters TargetComputer: Missing"
End If
If oArgs.Count &gt; 1 Then
WScript.Echo "Parameters OrchestrationName:" &amp; oArgs(1)
else
WScript.Echo "Parameters OrchestrationName: Missing"
End If
If oArgs.Count &gt; 2 Then
WScript.Echo "Parameters Option:" &amp; oArgs(2)
else
WScript.Echo "Parameters Option: Missing"
End If
Wscript.Quit -1
End If

strTargetComputer = oArgs(0)
strOrchestrationName = oArgs(1)
strOption = oArgs(2)
strNamespace = "\ROOT\MicrosoftBizTalkServer"
strQuery = "select * from MSBTS_Orchestration"

ExecActionOnOrchestration

Sub ExecActionOnOrchestration()
Dim strMessage
Dim objInstSet, objInst
Dim strFQOrchestrationName
On Error Resume Next
Set objInstSet = GetWMICollection(strTargetComputer, strNamespace, strQuery)

'Check for error condition before continuing.
If Err &lt;&gt; 0 Then
PrintWMIErrorThenExit Err.Description, Err.Number
End If

'If found, execute action, otherwise print error and end.
If objInstSet.Count &gt; 0 then
For Each objInst in objInstSet
strFQOrchestrationName = CStr(objInst.Properties_("Name").Value)
strFQOrchestrationName = strFQOrchestrationName &amp; ", " &amp; CStr(objInst.Properties_("AssemblyName").Value)
strFQOrchestrationName = strFQOrchestrationName &amp; ", " &amp; CStr(objInst.Properties_("AssemblyVersion").Value)
strFQOrchestrationName = strFQOrchestrationName &amp; ", " &amp; CStr(objInst.Properties_("AssemblyCulture").Value)
strFQOrchestrationName = strFQOrchestrationName &amp; ", " &amp; CStr(objInst.Properties_("AssemblyPublicKeyToken").Value)

'If the orchestration matches the one which needs to be Start/Stop
if strFQOrchestrationName = strOrchestrationName then
Select Case strOption
Case "1"
objInst.Start
strMessage = "The Orchestration was successfully Started."
Case "2"
objInst.Stop
strMessage = "The Orchestration was successfully Stopped."
Case "3"
objInst.Enlist
strMessage = "The Orchestration was successfully Enlisted."
Case "4"
objInst.Unenlist
strMessage = "The Orchestration was successfully Unenlisted."
End Select
If Err &lt;&gt; 0 Then
PrintWMIErrorThenExit strFQOrchestrationName &amp; ":" &amp; Err.Description, Err.Number
End If
End If
WScript.Echo
Next
Else
WScript.Echo "No Orchestration was found matching that Name."
End If
End Sub

Function GetWMICollection(TargetComputerToUse, strNamespace, strQuery)
Dim WbemSrv, WbemObjectSet
Set WbemSrv = Getobject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; TargetComputerToUse &amp; strNamespace)
Set WbemObjectSet = WbemSrv.ExecQuery(strQuery)
Set GetWMICollection = WbemObjectSet
End Function


'This subroutine deals with all errors using the WbemScripting object. Error descriptions
'are returned to the user by printing to the console.
Sub PrintWMIErrorThenExit(strErrDesc, nErrNum)
On Error Resume Next
Dim objWMIError : Set objWMIError = CreateObject("WbemScripting.SwbemLastError")

If (TypeName(objWMIError) = "Empty" ) Then
WScript.Echo strErrDesc &amp; " (HRESULT: " &amp; Hex(nErrNum) &amp; ")."
Else
WScript.Echo objWMIError.Description &amp; "(HRESULT: " &amp; Hex(nErrNum) &amp; ")."
Set objWMIError = Nothing
End If

'bail out
WScript.Quit 0
End Sub

'=================================================================================
' Publish resulting performance data / Create events
'=================================================================================

Sub CreateEvent(strSource, lngEventID, lngEventType, strMsg, strSrcComputer)
CreateEventEx strSource, lngEventID, lngEventType, strMsg, strSrcComputer, True
End Sub

Sub CreateReportEvent(strSource, lngEventID, lngEventType, strMsg, strSrcComputer)
CreateEventEx strSource, lngEventID, lngEventType, strMsg, strSrcComputer, False
End Sub

Sub CreateEventEx(strSource, lngEventID, lngEventType, strMsg, strSrcComputer, blnIncScriptName)
Dim oAPI
Set oAPI = CreateObject("Mom.ScriptAPI")
Call oAPI.LogScriptEvent(strSource, lngEventID, lngEventType, strMsg)
End Sub
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>