look at AD group and return display name

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
volleyman
Posts: 1
Joined: Fri Mar 02, 2007 6:46 am

look at AD group and return display name

Post by volleyman » Fri Mar 02, 2007 6:54 am

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

User avatar
jhicks
Posts: 1789
Joined: Sun Jan 21, 2007 11:31 pm

look at AD group and return display name

Post by jhicks » Fri Mar 02, 2007 7:33 am

The usename is the sAMAccountname. objNewGroup.WriteLine objUser.Get ("name") & " " & objUser.Get("sAMAccountName")Is that what you're looking for?

User avatar
ajlueth
Posts: 2
Joined: Fri May 18, 2007 6:15 am

look at AD group and return display name

Post by ajlueth » Fri May 18, 2007 6:31 am

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.

User avatar
jvierra
Posts: 12550
Joined: Tue May 22, 2007 9:57 am
Contact:

look at AD group and return display name

Post by jvierra » Fri May 18, 2007 8:03 am

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

User avatar
ajlueth
Posts: 2
Joined: Fri May 18, 2007 6:15 am

look at AD group and return display name

Post by ajlueth » Sun May 20, 2007 11:58 pm

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"

User avatar
jvierra
Posts: 12550
Joined: Tue May 22, 2007 9:57 am
Contact:

look at AD group and return display name

Post by jvierra » Mon May 21, 2007 12:18 am

I believe it's "members" and not "member"
You need to post the exact error. Guessing is too hard.

Locked