Solved

Count members in a AD group

Posted on 2010-09-15
2
1,854 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Here's a look at newsworthy articles and community happenings during the last month.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

690 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