AD RID Pool Free Data Source

Microsoft.Windows.Server.2012.R2.AD.RIDPool.Free.DataSource (DataSourceModuleType)

Data source for the AD RID Pool Free Performance Counter.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Frequencyint$Config/Frequency$FrequencyHow often the script is run
TimeoutSecondsint$Config/TimeoutSeconds$TimeoutTime out in Sec

Source Code:

<DataSourceModuleType ID="Microsoft.Windows.Server.2012.R2.AD.RIDPool.Free.DataSource" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Frequency" type="xsd:int"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Frequency" Selector="$Config/Frequency$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/Frequency$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/AD_RID_Pool_Free.vbs$</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>AD_RID_Pool_Free.vbs</Name>
<Contents><Script>'*************************************************************************
' Script Name - AD RID Pool Free
'
' Purpose - Obtains the current RID Pool percentage free
' - This is used to create a performance counter
'
' (c) Copyright 2012 R2, Microsoft Corporation, All Rights Reserved
' Proprietary and confidential to Microsoft Corporation
'*************************************************************************

Option Explicit

SetLocale("en-us")

On Error Resume Next

Sub Main()

Dim oBag, oAPI

Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()

' Get DC name so we can lookup RID pool info for this DC in AD
Dim oNTInfo, sComputerName
Set oNTInfo = CreateObject("WinNTSystemInfo")
sComputerName = oNTInfo.ComputerName

Dim oADO
Set oADO = CreateObject("ADODB.Connection")
oADO.Provider = "ADsDSOObject"
oADO.Open "Active Directory Provider"
If Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Unable to create ADODB Connection." &amp; GetErrorString(Err)
Call oAPI.Return(oBag)
Exit Sub
End If

' Connect to root DSE to get the default naming context
Dim oRootDSE
Set oRootDSE = GetObject("LDAP://RootDSE")
If Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Unable to contact Root DSE." &amp; GetErrorString(Err)
Call oAPI.Return(oBag)
Exit Sub
End If

Dim sDomainDN
sDomainDN = oRootDSE.Get("defaultNamingContext")

' Get Rid Allocation Pool by connecting to the Rid Set
Dim sLDAPQuery
sLDAPQuery = "CN=Rid Set,Cn=" &amp; sComputerName &amp; ",OU=Domain Controllers," &amp; sDomainDN

Dim oRidSet
Set oRidSet = GetObject("LDAP://" &amp; sLDAPQuery)
If Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Unable to get the Rid Set object: " &amp; _
sLDAPQuery &amp; vbCrLf &amp; GetErrorString(Err)
Call oAPI.Return(oBag)
Exit Sub
End If

on error goto 0
Dim orIDAllocationPool, iNextRid
Set orIDAllocationPool = oRidSet.Get("rIDAllocationPool")
iNextRid = oRidSet.Get("rIDNextRID")

' Get the high and low values from the IADsLargeInteger object to get the allocated pool
Dim iHighPart, iLowPart
iHighPart = orIDAllocationPool.HighPart
iLowPart = orIDAllocationPool.LowPart

' Calculate Rid pool percentage used to track as a counter
Dim iTotalPool
Dim iCurrentUsed
Dim iPercentageUsed

iTotalPool = iHighPart - iLowPart
iCurrentUsed = iNextRid - iLowPart
iPercentageUsed = Round((iCurrentUsed / iTotalPool) * 100, 0)


oBag.AddValue "StatusInstance", ""
oBag.AddValue "StatusValue", "" &amp; CInt(100 - iPercentageUsed)

Call oAPI.Return(oBag)

End Sub

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