Solved

Count members in a AD group

Posted on 2010-09-15
2
1,778 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
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 to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

790 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