BizTalk Group Discovery Module

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

This module discovers the BizTalk logical group on a specific run-time computer.

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.
ComputerNamestring$Config/ComputerName$Computer NameThe discovery is successful only if the name of the computer where the script is running matches this value.

Source Code:

<DataSourceModuleType ID="Microsoft.BizTalk.Server.2016.BizTalkGroupDiscovery" 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="ComputerName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
<OverrideableParameter ID="ComputerName" Selector="$Config/ComputerName$" ParameterType="string"/>
</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.BizTalkGroupDiscovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Property[Type="Microsoft.BizTalk.Server.2016.ServerRole"]/ComputerName$ $Target/Property[Type="Microsoft.BizTalk.Server.2016.BizTalkRuntimeRole"]/NetbiosComputerName$ $Config/ComputerName$</Arguments>
<ScriptBody><Script>
'Copyright (c) Microsoft Corporation. All rights reserved

'This script discovers BizTalk group on a computer passed as parameter
'$Config/ComputerName$. If computer name is not passed then it discovers group on
'a runtime computer with lowest server ID in the management database.

Option Explicit

Const HKEY_LOCAL_MACHINE = &amp;H80000002
Const GROUP_DISCOVERY_CONNECT_FAILURE = -1
Const GROUP_DISCOVERY_QUERY_FAILURE = -2

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

Dim SourceID, ManagedEntityId, TargetComputer
Dim ComputerName, NetbiosComputerName

SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
ComputerName = oArgs(2)
NetbiosComputerName = oArgs(3)
TargetComputer = null
if oArgs.Count &gt; 4 Then
TargetComputer = oArgs(4)
end if

Call GetBizTalkGroup()

Sub GetBizTalkGroup()
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; _
ComputerName &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 CreateObjectsAndRelations(byRef objAPI, byRef objDiscoveryData)
'Get management database data from registry
Dim MgmtDbName, MgmtDbServerName, GroupName
MgmtDbName = GetRegistryKeyValue("SOFTWARE\Microsoft\BizTalk Server\3.0\Administration", "MgmtDBName")
MgmtDbServerName = GetRegistryKeyValue("SOFTWARE\Microsoft\BizTalk Server\3.0\Administration", "MgmtDBServer")
GroupName = GetRegistryKeyValue("SOFTWARE\Microsoft\BizTalk Server\3.0\Administration", "BizTalkGroupName")

if IsNull(TargetComputer) then
Dim ObjError
Set ObjError = New Error

Dim defaultConnStr
defaultConnStr = "Server=" &amp; MgmtDbServerName &amp; ";Database=" &amp; MgmtDbName &amp; ";Trusted_Connection=yes"

Dim cnADOConnection
Set cnADOConnection = MomCreateObject("ADODB.Connection")
cnADOConnection.Provider = "SQLNCLI11"
cnADOConnection.ConnectionTimeout = 15

ObjError.Clear
On Error Resume Next
cnADOConnection.Open defaultConnStr
ObjError.Save
On Error Goto 0
If 0 &lt;&gt; Err.number then
'Error event to goin here
CreateObjectsAndRelations = GROUP_DISCOVERY_CONNECT_FAILURE
Exit Function
End If

Dim objResults

ObjError.Clear
On Error Resume Next
Set objResults = cnADOConnection.Execute("select top 1 * from adm_Server srv with (NoLock) order by srv.Id asc")
ObjError.Save
On Error Goto 0

If ObjError.Number &lt;&gt; 0 Then
' Error event to go in here
CreateObjectsAndRelations = GROUP_DISCOVERY_QUERY_FAILURE
If (objResults &lt;&gt; null) Then objResults.Close
Exit Function
End If

TargetComputer = CStr(objResults(1))
objResults.Close
end if

Dim DiscoverGroup
DiscoverGroup = false
if StrComp(TargetComputer, NetbiosComputerName, 1) = 0 then
DiscoverGroup = true
end if

if DiscoverGroup = true then
'Create group object
Dim oGroupInst
Set oGroupInst = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroup']$")
call oGroupInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroup']/Name$", GroupName)
call oGroupInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroup']/MgmtDbName$", MgmtDbName)
call oGroupInst.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BizTalkGroup']/MgmtDbServerName$", MgmtDbServerName)
call oGroupInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ComputerName)
call objDiscoveryData.AddInstance(oGroupInst)
end if
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>