Kenny Bones
Kenny Bones

Reputation: 5129

Get username from all users in specific group

I must be missing something here, or I'm blind or I've had too much coffee. Basically, I'm trying to get the username of each user in a specific group i AD. Then I want to take these username and pass those to a powershell script. But that's another case. This is probably a quick win for you guys.

Dim groupName
groupName = "LDAP://CN=groupname,OU=MailGroups,OU=Exchange,OU=MainContainer,DC=MyDomain,DC=com"
Set objGroup = GetObject(groupName)

For Each strUser in objGroup.Member
    Set objUser =  GetObject("LDAP://" & strUser.UserName)
Next

And I get this error message Object required: 'strUser' Why is this happening? strUser is right there! If I change the snippet a bit to this:

Set objGroup = GetObject(groupName)

For Each strUser in objGroup.Member
    Set objUser =  GetObject("LDAP://" & strUser)
    msgbox objUser.Name
Next

Then I get the result CN=Doe John in the message box for each member.

Upvotes: 0

Views: 10177

Answers (2)

Dan
Dan

Reputation: 266

This site will tell you more than you ever want to know about AD and VBS:

http://www.computerperformance.co.uk/vbscript/vbscript_group_enumerate_members.htm

Upvotes: 0

heximal
heximal

Reputation: 10517

try

For Each strUser in objGroup.Members

not Member but Member*s*

Upvotes: 1

Related Questions