Link to home
Create AccountLog in
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?
Avatar of Pete Long
Pete Long
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of Rahul Bansal
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
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer