Discover whether Backward Compatibility Computer hosts a Cluster Server

System.Mom.BackwardCompatibility.Computer.IsHostingMSCS.Discovery (Discovery)

Element properties:

TargetMicrosoft.Windows.Computer
EnabledTrue
Frequency900
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Microsoft.Windows.Cluster.PrivilegedAccount

Source Code:

<Discovery ID="System.Mom.BackwardCompatibility.Computer.IsHostingMSCS.Discovery" Enabled="true" Target="Windows!Microsoft.Windows.Computer">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="System.Mom.BackwardCompatibility.Computer">
<Property PropertyID="IsHostingMSCS"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="DS" RunAs="ClusterLibrary!Microsoft.Windows.Cluster.PrivilegedAccount" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>900</IntervalSeconds>
<SyncTime/>
<ScriptName>IsHostingMSCS.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetbiosComputerName$ </Arguments>
<ScriptBody><Script>
' Copyright (c) Microsoft Corporation. All rights reserved.
' Discover values for IsHostingMSCS
' System.Mom.BackwardCompatibility MP
' Targeted at Windows Server class - takes 4 or 5 arguments
' Works agentlessly and against Virtual servers (Wolfpack cluster)
'
'
' Arguments:
' Arg 0 : SourceID
' Arg 1 : MP Element ID
' Arg 2 : Computer FQDN name
' Arg 3 : Net bios computer name

'
'
'variables
Dim SourceID
Dim ManagedEntityID
Dim TargetComputer
Dim TargetComputerNetbios
Dim IsVirtualNode

Call Main

Sub Main()

'process arguments
Dim oParams
Set oParams = WScript.Arguments

If oParams.Count = 3 Then
WScript.Echo "NetbiosComputerName property has not been discovered yet, the script will ignore this and do discovery in the next interval!"
Wscript.Quit
End If

If oParams.Count &lt;&gt; 4 Then
ThrowScriptError "Invalid arguments specified.", null
WScript.Quit
End If

'set arguments
SourceID = oParams(0)
ManagedEntityId = oParams(1)
TargetComputer = oParams(2)
TargetComputerNetbios = oParams(3)

'run WMI query
Dim HostingMSCS
HostingMSCS = IsHostingMSCS()

'Submit Discovery data
SubmitDiscoveryData HostingMSCS
End Sub

'******************************************************************************
Function IsHostingMSCS()
Dim oWMIQuery
On Error Resume Next
Set oWMIQuery = WMIExecQuery("winmgmts://" &amp; TargetComputer &amp; "/root/cimv2", "SELECT * FROM Win32_Service WHERE Name=""ClusSvc"" and State=""Running"" and __Path LIKE '\\\\" &amp; TargetComputerNetbios &amp; "\\%'")
On Error Goto 0

If IsValidObject(oWMIQuery) Then
If oWMIQuery.Count &gt; 0 Then
IsHostingMSCS="true"
Exit Function
End If
End If

'we didn't execute the query or the query didn't return instances
IsHostingMSCS="false"
End Function

'******************************************************************************
Function WMIExecQuery(sNamespace, sQuery)
'
' WMIExecQuery :: Executes the WMI query and returns the result set.
'
'
Dim oWMI, oQuery, nInstanceCount

On Error Resume Next
Set oWMI = GetObject(sNamespace)
If IsEmpty(oWMI) Then
ThrowScriptErrorNoAbort "Unable to open WMI Namespace '" &amp; sNamespace &amp; "'. Check to see if the WMI service is enabled and running, and ensure this WMI namespace exists.", Err
Exit Function
End If

Set oQuery = oWMI.ExecQuery(sQuery)
If IsEmpty(oQuery) Or Err.Number &lt;&gt; 0 Then
ThrowScriptErrorNoAbort "The Query '" &amp; sQuery &amp; "' returned an invalid result set. Please check to see if this is a valid WMI Query.", Err
Exit Function
End If

'Determine if we queried a valid WMI class - Count will return 0 or empty
nInstanceCount = oQuery.Count
If Err.Number &lt;&gt; 0 Then
ThrowScriptErrorNoAbort "The Query '" &amp; sQuery &amp; "' did not return any valid instances. Please check to see if this is a valid WMI Query.", Err
Exit Function
End If
On Error Goto 0

Set WMIExecQuery = oQuery

Set oQuery = Nothing
Set oWMI = Nothing
End Function

'******************************************************************************
Function SubmitDiscoveryData(ByVal sMSCS)
Dim oAPI, oDiscoveryData

Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

Dim oInstance
Set oInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='System.Mom.BackwardCompatibility.Computer']$")

With oInstance
.AddProperty "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer
.AddProperty "$MPElement[Name='System.Mom.BackwardCompatibility.Computer']/IsHostingMSCS$", sMSCS
End With

oDiscoveryData.AddInstance(oInstance)
oAPI.Return(oDiscoveryData)
End Function

'******************************************************************************
Function ThrowScriptError(Byval sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'
Dim iErrNum
iErrNum = 1
If not IsNull(oErr) Then
oErrNum = oErr.Number
sMessage = sMessage &amp; oErr.Description
End If

' Calling this externally due to Err.Raise's poor handling of ByRef Variants
Dim raiseError
raiseError = "Err.Raise " &amp; iErrNum &amp; ", ""DiscoverVirtualServerType"", """ &amp; sMessage &amp; """"
Execute raiseError

End Function


'******************************************************************************
Function ThrowScriptErrorNoAbort(Byval sMessage, ByVal oErr)
'
' ThrowScriptError :: Creates an event and sends it back to the mom server
'
'
On Error Resume Next

ThrowScriptError sMessage, oErr
Wscript.echo Err.Description
Err.Clear

On Error Goto 0

End Function


'******************************************************************************
Function IsValidObject(ByVal oObject)
IsValidObject = False

If IsObject(oObject) Then
If Not oObject Is Nothing Then
IsValidObject = True
End If
End If
End Function

</Script></ScriptBody>
<TimeoutSeconds>120</TimeoutSeconds>
<EventPolicy>
<StdOutMatches/>
</EventPolicy>
</DataSource>
</Discovery>