Solved

Count members in a AD group

Posted on 2010-09-15
2
1,704 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
Comment Utility
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
Comment Utility
On shot.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now