Page 1 of 1

look at AD group and return display name

Posted: Fri Mar 02, 2007 5:54 am
by volleyman
i have a script (not written by me) for which I can enter an AD group name and it writes the display name of all members to a text file. I would also like to add the username next to the display name but can't figure it out. here is what I have:'This script will export the list of members of a Group.'Input Variable for AD Group set by user running scriptGroupname = InputBox("Enter Group Name such as CLAS0Users")'Sets AD path to GroupsSet objGroup = GetObject("LDAP://" & "CN=" & Groupname & ",OU=Groups,OU=Las Vegas,OU=CCI,DC=CORP,DC=COX,DC=COM")'Creates Output Text File and HeaderSet objFS = CreateObject("Scripting.FileSystemObject")Set objNewGroup = objFS.CreateTextFile("GroupListing " & groupname & ".txt")objNewGroup.WriteLine "Members of " & GroupnameMemberOf = objGroup.GetEx("member")For Each member in MemberOfSet objUser = GetObject("LDAP://" & member)'Uncomment next line if debugging required'on Error Resume Next objNewGroup.WriteLine objUser.Get ("name")Next Wscript.echo "Script is done"any help would be appreciated.Z

look at AD group and return display name

Posted: Fri Mar 02, 2007 6:33 am
by jhicks
The usename is the sAMAccountname. objNewGroup.WriteLine objUser.Get ("name") & " " & objUser.Get("sAMAccountName")Is that what you're looking for?

look at AD group and return display name

Posted: Fri May 18, 2007 6:31 am
by ajlueth
How do I use this to grab members of all groups in a particular OU, rather than going one group at a time?

Thanks in advance.

look at AD group and return display name

Posted: Fri May 18, 2007 8:03 am
by jvierra
GEt teh OU using LDAP tehn enumerte all of it's objects and apply teh above code to each object that is a group.

You could also filter for "objectClass='group'"

The above example would be modified like this for teh OU:

Code: Select all

Set objGroup = GetObject(LDAP://"OU=ouName,OU=parentOUNames,DC=CORP,DC=COX,DC=COM")

jvierra2007-05-18 15:03:56

look at AD group and return display name

Posted: Sun May 20, 2007 11:58 pm
by ajlueth
Thanks much for the response, but I'm getting stuck. It keeps erring the on line *memberof - objgroup.getex("member")*. I'm not sure what to fix, as I'm pretty new to the world of scripting. Any help is appreciated. Here's the modified script from what was previously posted.

Set objGroup = GetObject("LDAP://ou=ou1,OU=Groups,DC=domain,DC=COM")
'Creates Output Text File and HeaderSet objFS = CreateObject("Scripting.FileSystemObject")Set objNewGroup = objFS.CreateTextFile("Grouplist.csv")objNewGroup.WriteLine "Members of " & Groupname
MemberOf = objGroup.GetEx("member")For Each member in MemberOfSet objUser = GetObject("LDAP://" & member)'Uncomment next line if debugging required'on Error Resume Next objNewGroup.WriteLine objUser.Get ("name")
Next Wscript.echo "Script is done"

look at AD group and return display name

Posted: Mon May 21, 2007 12:18 am
by jvierra
I believe it's "members" and not "member"
You need to post the exact error. Guessing is too hard.