<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." & 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." & GetErrorString(Err)
Call oAPI.Return(oBag)
Exit Sub
End If
Dim sDomainDN
sDomainDN = oRootDSE.Get("rootDomainNamingContext")
' Get Rid Allocation Pool by connecting to the Rid Set
Dim sLDAPQuery
sLDAPQuery = "CN=Rid Set,Cn=" & sComputerName & ",OU=Domain Controllers," & sDomainDN
Dim oRidSet
Set oRidSet = GetObject("LDAP://" & sLDAPQuery)
If Err Then
oBag.AddValue "State", "BAD"
oBag.AddValue "ErrorString", "Unable to get the Rid Set object: " & _
sLDAPQuery & vbCrLf & 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