PDA

View Full Version : Count members of AD group from Excel



reeksi
10-17-2012, 09:46 AM
Hi All,

Im trying to create a spreadsheet function that will list the number of members in certain groups. for example, if i type "NumberOfMembers(Groupname)" in a cell, i wish for it to return the number of members in that particular group.


Ive put this following together that works as a script, but need to change this into an excel function:

Set objGroup = GetObject("LDAP://CN=App_Compass,OU=Applications,OU=Security,OU=CRCL,OU=Groups,DC=crcl,DC=loc al")


i = 0

Set objDictionary = CreateObject("Scripting.Dictionary")

For Each strUser in objGroup.Member
i = i + 1

Set objMember = GetObject("LDAP://" & strUser)
strType = objMember.Class

If Not objDictionary.Exists(strType) Then
objDictionary.Add strType, "1"
Else
objDictionary.Item(strType) = objDictionary.Item(strType) + 1
End If
Next

Wscript.Echo "Total members in the group: " & i
Wscript.Echo

For Each objType in objDictionary
Wscript.Echo objType & ": " & objDictionary.Item(objType)
Next

Many thank in advance for the help!