Friday, September 21, 2012

Vbs Script To Count Users In An Active Directory Domain

This by request Vbs script will return the total number of users found in the specified domain.

Note: Change DomainName to your AD domain name.

Vbs Script:

Const Ads_Scope_SubTree = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = Ads_Scope_SubTree

objCommand.CommandText = _
"Select Name From 'LDAP://DC = DomainName, DC = Com' Where objectCategory = 'Person'"

Set objRecordSet = objCommand.Execute
MsgBox "Total Number Of Users Found : " & objRecordSet.RecordCount

Original Post