Avatar of lanman777
lanman777
 asked on

Extracting all user names from groups

From our Active Directory, in Users and Computers, in my Groups folder.
I have many groups that I would like to extract the users names from
and try to avoid going group to group to extract each name manually.
Is there a way to automate or script this information extraction?
Active DirectoryVB Script

Avatar of undefined
Last Comment
RobSampson

8/22/2022 - Mon
Pete Long

Copy all AD users to a text file

From https://www.experts-exchange.com/questions/20698009/Exports-Group-list-to-a-text-file.html#9073544

Being a scripting nut, I tend to approach these kind of problems from a scripting standpoint.

copy and paste the code below into "Mattisastud.vbs" and then run it.

Then open the GroupMembership.txt file and it should have everything you need.  
If you want to view the machine accounts also, uncomment the commmented line...

-=-=-=-=-=-=-=-=-=-=-=-=-=-  Code Below  -=-=-=-=-=-=-=-=-=-=-=-=-=-  

Dim myNetwork
Set myNetwork = CreateObject("Wscript.Network")

strDomain = myNetwork.UserDomain

Set objDomain = getobject("WinNT://" & strDomain) 'Grab the domain object
objDomain.filter = Array("Group") 'Filter for just computers.

Dim myFSO
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set myFile = myFSO.CreateTextFile("GroupMembership.txt",1)

myOutput = ""

For each objGroup in objDomain
    myOutput = myOutput & objGroup.Name & vbcrlf
   For Each objUser in objGroup.Members
'          myOutput = myOutput & vbtab & objUser.Name & vbcrlf
         If right(objUser.name,1) <> "$" Then
              myOutput = myOutput & vbtab & objUser.Name & vbcrlf
         End if
   Next
Next

WScript.Echo myOutput
myfile.writeline myOutput

-=-=-=-=-=-=-=-=-=-=-=-=-=-  End Code  -=-=-=-=-=-=-=-=-=-=-=-=-=-  

CREDIT To :MAT

*****Other Links*****

How can I create a file containing all the user names in my domain?
http://www.jsiinc.com/subl/tip5500/rh5531.htm

How can I produce a list of the user logon names in my domain?
http://www.jsiinc.com/subi/tip4400/rh4490.htm

Run a Group/User or User/Group report.
http://www.jsiinc.com/SUBB/tip0700/rh0748.htm
Rahul Bansal

Easiest way

dsget command with the DNs of the groups... It can even export the indirect members using -expand switch.

ADExpert
ASKER CERTIFIED SOLUTION
RobSampson

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck