DobotJr
DobotJr

Reputation: 4049

Get SAMAccountNames for all users in AD group

I'm looking for a vbscript that will retrieve the SAMAccountNames for all members in a Active Directory Group.

Thanks.

Upvotes: 0

Views: 4158

Answers (1)

JPBlanc
JPBlanc

Reputation: 72620

Here is the script you are looking for :

'  Begining from a given group
Dim strGrp
strGrp = "cn=g1,ou=ou,dc=societe,dc=fr"
Set objGroup = GetObject ("LDAP://"& strGrp)
objGroup.getInfo

arrMemberOf = objGroup.GetEx("member")

' Loop = For Each .... Next 
' WScript.Echo "Members of Group "
For Each strMember in arrMemberOf
   WScript.echo strMember
   Set objUser = GetObject ("LDAP://"& strMember)
   sAMAccountName = objUser.GetEx("sAMAccountName")
   WScript.echo sAMAccountName(0)
Next
Wscript.Quit

Here is a site where you can get help.

Upvotes: 1

Related Questions