Global Catalog Availability Script Data source

Microsoft.Windows.AD.DomainMemberPerspective.Availability.GlobalCatalog.DataSource (DataSourceModuleType)

Data source for the Global Catalog availability monitors.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval Seconds
ErrorThresholdint$Config/ErrorThreshold$Error threshold for the number of available Global Catalogs
WarnThresholdint$Config/WarnThreshold$Warning threshold for the number of available Global Catalogs
TimeoutSecondsint$Config/TimeoutSeconds$Timeout Seconds

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.AD.DomainMemberPerspective.Availability.GlobalCatalog.DataSource" Accessibility="Internal">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="IntervalSeconds" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ErrorThreshold" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WarnThreshold" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/>
<OverrideableParameter ID="ErrorThreshold" ParameterType="int" Selector="$Config/ErrorThreshold$"/>
<OverrideableParameter ID="WarnThreshold" ParameterType="int" Selector="$Config/WarnThreshold$"/>
<OverrideableParameter ID="TimeoutSeconds" ParameterType="int" Selector="$Config/TimeoutSeconds$"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/GlobalCatalogAvailability.vbs$ $Config/ErrorThreshold$ $Config/WarnThreshold$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>GlobalCatalogAvailability.vbs</Name>
<Contents><Script>'*************************************************************************
' Script Name - GlobalCatalogAvailability
'
' Purpose - Ensure that the minimum number of GCs specified are online
'
' (c) Copyright 2014, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

SetLocale("en-us")

Sub Main()
Dim oAPI, oBag, oParams, oRootDSE, rsGCs, strQuery, sError
Dim iMinimumConfiguredGCs, iWarnAvailableGCs, iErrorAvailableGCs, oADOConn
Dim strDNSHostName, strConfigNamingContext, strFailureMessage
Dim oNTDSASettings, iAvailableGCs

Set oAPI = CreateObject("Mom.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()
Set oParams = WScript.Arguments

if oParams.Count &lt;&gt; 2 then
sError = "The number of command line arguments is incorrect: " &amp; vbCrLf &amp; _
"Expected: 2" &amp; vbCrLf &amp; _
"Actual: " &amp; oParams.Count

oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", sError

Call oAPI.Return(oBag)
Exit Sub
End if

iErrorAvailableGCs = CInt(oParams(0))

if iErrorAvailableGCs &lt; 1 then
iErrorAvailableGCs = 1
End if

iWarnAvailableGCs = CInt(oParams(1))

if iWarnAvailableGCs &lt; 1 then
iWarnAvailableGCs = 2
End if

On Error Resume Next

' Obtain the RootDSE of any GC that this client computer can connect to.
Set oRootDSE = GetObject("GC://RootDSE")
If 0 &lt;&gt; Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Unable to bind to the rootDSE of any GC in the domain." &amp; GetErrorString(Err)
oAPI.AddItem oBag

Call oAPI.Return(oBag)
Exit Sub
End If

' Now query the root DSE to get the site of the DC
strDNSHostName = oRootDSE.Get("DNSHostName")
strConfigNamingContext = oRootDSE.Get("ConfigurationNamingContext")
If 0 &lt;&gt; Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Error attempting to read the 'ConfigurationNamingContext' of the GC '" &amp; strDNSHostName &amp; "'." &amp; GetErrorString(Err)
oAPI.AddItem oBag

Call oAPI.Return(oBag)
Exit Sub
End If

' Query AD to determine all the configured GCs
Set oADOConn = CreateObject("ADODB.Connection")
If Err &lt;&gt; 0 Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Error creating an ADODB connection." &amp; GetErrorString(Err)
oAPI.AddItem oBag

Call oAPI.Return(oBag)
Exit Sub
End If

oADOConn.Provider = "ADSDsOObject"
oADOConn.Open "ADs Provider"
If Err &lt;&gt; 0 Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Error initializing the ADODB connection." &amp; GetErrorString(Err)
oAPI.AddItem oBag

Call oAPI.Return(oBag)
Exit Sub
End If

strQuery = "&lt;LDAP://" &amp; strDNSHostName &amp; "/CN=Sites," &amp; strConfigNamingContext &amp; "&gt;;(&amp;(objectClass=nTDSDSA)(options:1.2.840.113556.1.4.803:=1)(!isDeleted=TRUE));adspath,cn;subtree"
Set rsGCs = oADOConn.Execute(strQuery)
If 0 &lt;&gt; Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Error executing the following query: '" &amp; strQuery &amp; "'." &amp; GetErrorString(Err)
oAPI.AddItem oBag

Call oAPI.Return(oBag)
Exit Sub
End If

iAvailableGCs = 0
rsGCs.MoveFirst
Do Until rsGCs.EOF Or iAvailableGCs &gt;= iWarnAvailableGCs
Set oNTDSASettings = GetObject(rsGCs.Fields("adspath"))

Err.Clear

If IsObject(oNTDSASettings) Then
Dim oServer, strGCDNSHostName, oGC, strTemp, oPerfOS
Set oServer = GetObject(oNTDSASettings.Parent)

If 0 &lt;&gt; Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Error getting the following object: '" &amp; oNTDSASettings.Parent &amp; "'." &amp; GetErrorString(Err)
oAPI.AddItem oBag

Call oAPI.Return(oBag)
Exit Sub
End If

strGCDNSHostName = oServer.Get("DNSHostName")
Set oGC = GetObject("GC://" &amp; strGCDNSHostName &amp; "/RootDSE")

' Attempt to retrieve a property from the object (to force ADSI to actually connect).
strTemp = oGC.Get("DNSHostName")
If 0 = Err Then
iAvailableGCs = iAvailableGCs + 1
End If
End If

rsGCs.MoveNext
Loop

If iAvailableGCs &lt; iErrorAvailableGCs Then
strFailureMessage = "The number of GCs available is lower than the specified threshold." &amp; vbCrLf &amp; _
"Available GCs: " &amp; iAvailableGCs &amp; vbCrLf &amp; _
"Error Threshold: " &amp; iErrorAvailableGCs &amp; vbCrLf &amp; _
"Warning Threshold: " &amp; iWarnAvailableGCs

oBag.AddValue "State","ERROR"
oBag.AddValue "ErrorString", strFailureMessage
oAPI.AddItem oBag
ElseIf iAvailableGCs &lt; iWarnAvailableGCs Then
strFailureMessage = "The number of GCs available is lower than the specified threshold." &amp; vbCrLf &amp; _
"Available GCs: " &amp; iAvailableGCs &amp; vbCrLf &amp; _
"Error Threshold: " &amp; iErrorAvailableGCs &amp; vbCrLf &amp; _
"Warning Threshold: " &amp; iWarnAvailableGCs

oBag.AddValue "State","WARN"
oBag.AddValue "ErrorString", strFailureMessage
oAPI.AddItem oBag
Else
oBag.AddValue "State", "GOOD"
oAPI.AddItem oBag
End If

oAPI.ReturnItems
End Sub

'******************************************************************************
Function GetErrorString(oErr)
'
' Purpose: Attempts to find the description for an error if an error with
' no description is passed in.
'
' Parameters: oErr, the error object
'
' Return: String, the description for the error. (Includes the error code.)
'
Dim lErr, strErr
lErr = oErr
strErr = oErr.Description

On Error Resume Next
If 0 &gt;= Len(strErr) Then
' If we don't have an error description, then check to see if the error
' is a 0x8007xxxx error. If it is, then look it up.
Const ErrorMask = &amp;HFFFF0000
Const HiWord8007 = &amp;H80070000
Const LoWordMask = 65535 ' This is equivalent to 0x0000FFFF

If (lErr And ErrorMask) = HiWord8007 Then
' Attempt to use 'net helpmsg' to get a description for the error.
Dim oShell
Set oShell = CreateObject("WScript.Shell")
If Err = 0 Then
Dim oExec
Set oExec = oShell.Exec("net helpmsg " &amp; (lErr And LoWordMask))

Dim strMessage, i
Do
strMessage = oExec.stdout.ReadLine()
i = i + 1
Loop While (Len(strMessage) = 0) And (i &lt; 5)

strErr = strMessage
End If
End If
End If

GetErrorString = vbCrLf &amp; "The error returned was: '" &amp; strErr &amp; "' (0x" &amp; Hex(lErr) &amp; ")"
End Function

Call Main()
</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>