bsharath
asked on
Vbs script to get group membership count. Does not get actual count for some groups.
Hi,
Vbs script to get group membership count. Does not get actual count for some groups.
For some groups that are 0 it gets the previously scanned group no's
Can anyone help to fix the issue.
REgards
sharath
Vbs script to get group membership count. Does not get actual count for some groups.
For some groups that are 0 it gets the previously scanned group no's
Can anyone help to fix the issue.
REgards
sharath
On Error Resume Next
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
domainPath = "DC=lth,Dc=local"
orgUnitPathForGroups = "OU=Distri,OU=Offices"
objCommand.CommandText = _
"SELECT Name FROM 'LDAP://" & orgUnitPathForGroups & "," & domainPath & "' WHERE objectCategory='group'"
Set objGroupRecordSet = objCommand.Execute
objGroupRecordSet.MoveFirst
Do Until objGroupRecordSet.EOF
Set objGroup = GetObject _
("LDAP://cn=" & objGroupRecordSet.Fields("Name").Value & "," & orgUnitPathForGroups & "," & domainPath)
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
i = 0
' WScript.Echo "Members:"
For Each strMember in arrMemberOf
' WScript.echo " " & strMember
i = i+1
Next
Wscript.Echo "Group: [" & objGroupRecordSet.Fields("Name").Value & "] Members: " & i
objGroupRecordSet.MoveNext
Loop
ASKER
Thanks
Can you please make the changes in the whole code
Can you please make the changes in the whole code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get a lot of 0's zeros as membership count. Where as there are members
arrMemberOf = objGroup.GetEx("member")
in line 29, in combination with the leading "on error resume next"....
When a group is empty, the "member" attribute doesn't exist and therefor cannot be read...so this is a runtime error normally, but in your case the script continues, and the "arrMemberOf" will be the same value as the last group!!
Easy solution: Set the "arrMemberOf" to an empty array BEFORE you try to read this:
arrMemberOf = Array()
arrMemberOf = objGroup.GetEx("member")
Philipp