BizTalk Server Role Discovery Module

Microsoft.BizTalk.Server.2016.BizTalkRoleDiscovery (DataSourceModuleType)

This module discovers the server role instances associated with a BizTalk group - run-time and Business Rule Engine - on different computers associated with the group.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsMicrosoft.BizTalk.DiscoveryAccount
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DataSource DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval SecondsThis is the interval (in seconds) at which the script associated with the module is run.
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:

<DataSourceModuleType ID="Microsoft.BizTalk.Server.2016.BizTalkRoleDiscovery" Accessibility="Public" RunAs="Microsoft.BizTalk.DiscoveryAccount" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element name="Option" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>Microsoft.BizTalk.Server.2016.BizTalkRoleDiscovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$ $Config/Option$</Arguments>
<ScriptBody><Script>
'Copyright (c) Microsoft Corporation. All rights reserved

'This script discovers the BizTalk server roles in a specified computer
'based on parameter $Config/Option$.
'Option 1 - BizTalk runtime role, BizTalk group deployment and containment
'of runtime in group deployment.
'Option 2 - BizTalk rules engine role, BizTalk group deployment and containment
'of rules engine in group deployment.
'BAM role is always discovered with any of the options, and its containment in
'group deployment.

Option Explicit

Const HKEY_LOCAL_MACHINE = &amp;H80000002

Dim oArgs
Set oArgs = WScript.Arguments
if oArgs.Count &lt; 5 Then
Wscript.Quit -1
End If

Dim SourceID, ManagedEntityId, TargetComputer, NetbiosComputerName, OptionID

SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
TargetComputer = oArgs(2)
NetbiosComputerName = oArgs(3)
OptionID = oArgs(4)

Call GetBizTalkRoles()

Sub GetBizTalkRoles()
Dim objAPI, objDiscoveryData

Set objAPI = CreateObject("MOM.ScriptAPI")
Set objDiscoveryData = objAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

CreateObjectsAndRelations objAPI, objDiscoveryData
Call objAPI.Return(objDiscoveryData)
End Sub

Function GetRegistryKeyValue(strKey, strValue)
Dim sMethod, hTree
Dim oRegistry, oMethod, oInParam, oOutParam
sMethod = "GetStringValue"
hTree = HKEY_LOCAL_MACHINE

Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//" &amp; _
TargetComputer &amp; "/root/default:StdRegProv")

Set oMethod = oRegistry.Methods_(sMethod)
Set oInParam = oMethod.inParameters.SpawnInstance_()

oInParam.hDefKey = hTree
oInParam.sSubKeyName = strKey
oInParam.sValueName = strValue

Set oOutParam = oRegistry.ExecMethod_(sMethod, oInParam)
GetRegistryKeyValue = oOutParam.Properties_("sValue")
if IsNull(GetRegistryKeyValue) then
GetRegistryKeyValue = ""
end if
End Function

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

Function CreateObjectsAndRelations(byRef objAPI, byRef objDiscoveryData)
'Get management database data from registry
Dim MgmtDbName, MgmtDbServerName
MgmtDbName = GetRegistryKeyValue("SOFTWARE\Microsoft\BizTalk Server\3.0\Administration", "MgmtDBName")
MgmtDbServerName = GetRegistryKeyValue("SOFTWARE\Microsoft\BizTalk Server\3.0\Administration", "MgmtDBServer")

'Get additional data using WMI
Dim strWMIBaseClass, strGroupQuery
strWMIBaseClass = "MicrosoftBizTalkServer"
strGroupQuery = "select * from MSBTS_GroupSetting where MgmtDbName='" &amp; Replace(MgmtDbName, "\", "\\") &amp; "' and MgmtDbServerName='" &amp; Replace(MgmtDbServerName, "\", "\\") &amp; "'"
Dim GroupWbemObjSet, WbemGroupObject
Set GroupWbemObjSet = GetWMICollection(TargetComputer, strWMIBaseClass, strGroupQuery)

Dim strEval
For Each WbemGroupObject In GroupWbemObjSet
'Create group deployment object
Dim oGroupDeploymentInst
Set oGroupDeploymentInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroupDeployment']$")
strEval = Eval(IsObject(WbemGroupObject.Properties_("Name")))
If (strEval &lt;&gt; "False") Then
call oGroupDeploymentInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroupDeployment']/Name$", WbemGroupObject.Properties_("Name").value)
End If
call oGroupDeploymentInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroupDeployment']/MgmtDbName$", MgmtDbName)
call oGroupDeploymentInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroupDeployment']/MgmtDbServerName$", MgmtDbServerName)
call objDiscoveryData.AddInstance(oGroupDeploymentInst)

Dim oTargetInst
oTargetInst = null
Dim RelationshipClassId
Select Case OptionID
case "1"
Dim strHostInstanceQuery
strHostInstanceQuery = "select * from MSBTS_HostInstance where ClusterInstanceType != 3 and RunningServer = '" &amp; NetbiosComputerName &amp; "'"
Dim HostInstanceWbemObjSet
Set HostInstanceWbemObjSet = GetWMICollection(TargetComputer, strWMIBaseClass, strHostInstanceQuery)
'Discover runtime role if there is atleast one host instance on the computer
if (HostInstanceWbemObjSet.Count &gt; 0) then
'Get SSO database data from registry
Dim SSODbName, SSODbServerName
SSODbName = GetRegistryKeyValue("SOFTWARE\Microsoft\ENTSSO\SQL", "Database")
SSODbServerName = GetRegistryKeyValue("SOFTWARE\Microsoft\ENTSSO\SQL", "Server")

'Create runtime role object
Set oTargetInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']$")
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']/NetbiosComputerName$", NetbiosComputerName)
strEval = Eval(IsObject(WbemGroupObject.Properties_("SubscriptionDBName")))
If (strEval &lt;&gt; "False") Then
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']/MsgBoxDbName$", WbemGroupObject.Properties_("SubscriptionDBName").value)
End If
strEval = Eval(IsObject(WbemGroupObject.Properties_("SubscriptionDBServerName")))
If (strEval &lt;&gt; "False") Then
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']/MsgBoxDbServerName$", WbemGroupObject.Properties_("SubscriptionDBServerName").value)
End If
strEval = Eval(IsObject(WbemGroupObject.Properties_("TrackingDBName")))
If (strEval &lt;&gt; "False") Then
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']/TrackingDbName$", WbemGroupObject.Properties_("TrackingDBName").value)
End If
strEval = Eval(IsObject(WbemGroupObject.Properties_("TrackingDBServerName")))
If (strEval &lt;&gt; "False") Then
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']/TrackingDbServerName$", WbemGroupObject.Properties_("TrackingDBServerName").value)
End If
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']/SSODbName$", SSODbName)
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole']/SSODbServerName$", SSODbServerName)

'Set relation name
RelationshipClassId = "$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroupDeploymentContainsServerRole']$"
end if
case "2"
Dim regKey, regValue
regKey = "SYSTEM\CurrentControlSet\Services\RuleEngineUpdateService"
regValue = GetRegistryKeyValue(regKey, "DisplayName")
'Discover rule engine role if the rule engine update service is present on the computer
if Not(IsNull(regValue) or IsEmpty(regValue) or regValue = "") then
'Create rule engine role object
Set oTargetInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.RuleEngineRole']$")
strEval = Eval(IsObject(WbemGroupObject.Properties_("RuleEngineDBName")))
If (strEval &lt;&gt; "False") Then
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.RuleEngineRole']/RulesDbName$", WbemGroupObject.Properties_("RuleEngineDBName").value)
End If
strEval = Eval(IsObject(WbemGroupObject.Properties_("RuleEngineDBServerName")))
If (strEval &lt;&gt; "False") Then
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.RuleEngineRole']/RulesDbServerName$", WbemGroupObject.Properties_("RuleEngineDBServerName").value)
End If

'Set relation name
RelationshipClassId = "$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroupDeploymentContainsServerRole']$"
end if
End Select

if Not(IsNull(oTargetInst)) then
'Set common properties
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.ServerRole']/ComputerName$", TargetComputer)
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.ServerRole']/MgmtDbName$", MgmtDbName)
call oTargetInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.ServerRole']/MgmtDbServerName$", MgmtDbServerName)
call oTargetInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call objDiscoveryData.AddInstance(oTargetInst)
CreateRelationShip objDiscoveryData, oGroupDeploymentInst, oTargetInst, RelationshipClassId
end if

'Create BAM role object for any biztalk hosted role
Dim oBAMRole
Set oBAMRole = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRole']$")
strEval = Eval(IsObject(WbemGroupObject.Properties_("BamDBName")))
If (strEval &lt;&gt; "False") Then
call oBAMRole.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRole']/BAMPrimaryImportDbName$", WbemGroupObject.Properties_("BamDBName").value)
End If
strEval = Eval(IsObject(WbemGroupObject.Properties_("BamDBServerName")))
If (strEval &lt;&gt; "False") Then
call oBAMRole.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRole']/BAMPrimaryImportDbServerName$", WbemGroupObject.Properties_("BamDBServerName").value)
End If
call objDiscoveryData.AddInstance(oBAMRole)

CreateRelationShip objDiscoveryData, oGroupDeploymentInst, oBAMRole, "$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroupDeploymentContainsBAM']$"
Next
End Function

Function CreateRelationShip(byRef objDiscoveryData, SourceObject, TargetObject, strRelationShipClassId)
Dim objRelation
Set objRelation = objDiscoveryData.CreateRelationshipInstance(strRelationShipClassId)
objRelation.Source = SourceObject
objRelation.Target = TargetObject
objDiscoveryData.AddInstance objRelation
End Function

Function MomCreateObject(ByVal sProgramId)
Dim ObjError
Set ObjError = New Error

On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)
ObjError.Save
On Error Goto 0

If ObjError.Number &lt;&gt; 0 Then WScript.Quit
End Function

Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>