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.
This topic is 16 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
volleyman
Posts: 1
Last visit: Fri Mar 02, 2007 5:54 am

look at AD group and return display name

Post 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
User avatar
jhicks
Posts: 1789
Last visit: Mon Oct 19, 2015 9:21 am

look at AD group and return display name

Post by jhicks »

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
Last visit: Sun May 20, 2007 11:58 pm

look at AD group and return display name

Post 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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

look at AD group and return display name

Post 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
User avatar
ajlueth
Posts: 2
Last visit: Sun May 20, 2007 11:58 pm

look at AD group and return display name

Post 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"
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

look at AD group and return display name

Post by jvierra »

I believe it's "members" and not "member"
You need to post the exact error. Guessing is too hard.
This topic is 16 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked