Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Count members in a AD group

Posted on 2010-09-15
2
Medium Priority
?
2,003 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

How to deal with a specific error when using the Enable-RemoteMailbox cmdlet to create a mailbox in the cloud-based service, for an existing user in an on-premises Active Directory.
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

610 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