Get Group Name and Member Count

The following script will display all groups and their member count within a domain.

strNamingContext = “defaultNamingContext”
strConnectionString = “Provider=ADsDSOObject”
strFilter= “ObjectCategory=’group’”

‘[Functions] ****************************************

Function removeCN(inputString)
  Dim textValue 
     textValue = inputString
 Dim textLength
     textLength = Len(textValue)
   textValue = Right(textValue, textLength-3)

      removeCN = textValue   
End Function

‘****************************************************

Set objAdRootDSE = GetObject(”LDAP://RootDSE“)
Set objRS = CreateObject(”ADODB.RecordSet”)

 objNamingContext = objAdRootDSE.Get(strNamingContext)

 strSQLQuery = “SELECT * FROM ‘LDAP://” &_
         objNamingContext &_
         “‘ WHERE ” & strFilter &_
         “ORDER BY NAME”

objRS.Open strSQLQuery, strConnectionString

On Error Resume Next

Do until objRS.eof
 Set objGroup = GetObject(objRS.Fields.Item(0))
 strGroup = removeCN(objGroup.Name)

        membercounter = 0

 For each oMember in objGroup.Members

  memberCounter = membercounter + 1
 Next
 
 WScript.Echo(strGroup & “,” & memberCounter)

 Set memberCounter = nothing
objRS.MoveNext

Loop

Powered by WordPress with [GimpStyle]
Entries and comments feeds.