Solved

Count members in a AD group

Posted on 2010-09-15
2
1,754 Views
Last Modified: 2012-05-10
Can you please help me with this small code?
 
The below script works fine if the group is set to Group-1 and gives me a proper count (Group-1 has 87 members). But once i change the group name to Group-2 (Group-2 has only one member) the script throws an error (attached). But once the count becomes 2 in Group-2 the script works fine. Please help
i = 0
Set objGroup = GetObject("LDAP://CN=GG-IN-VDI Group-1,OU=Server Groups,OU=Groups,OU=FirstOU,DC=in,DC=domain,DC=org")
For Each strUser in objGroup.Member
i = i + 1
Next
Msgbox i

Open in new window

error.jpg
0
Comment
Question by:Dhiraj Mutha
2 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 125 total points
ID: 33688910
Hi, you need to check the TypeName of the Member property.

Regards,

Rob.
i = 0
Set objGroup = GetObject("LDAP://CN=GG-IN-VDI Group-1,OU=Server Groups,OU=Groups,OU=FirstOU,DC=in,DC=domain,DC=org")
If TypeName(objGroup.Member) = "Empty" Then
	' No members
ElseIf TypeName(objGroup.Member) = "String" Then
	i = i + 1
Else
	For Each strUser in objGroup.Member
	i = i + 1
	Next
End If
Msgbox i

Open in new window

0
 
LVL 14

Author Comment

by:Dhiraj Mutha
ID: 33689007
On shot.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question