Solved

Using ACTIVE DIRECTORY how can I print out a list of all Users and their UserNames?

Posted on 2006-11-29
13
281 Views
Last Modified: 2011-09-20
I have close to 400 users in AD and I don't want to have to look at them one at a time!   If I could get a list of just the UserNames I'd be in extacy!
0
Comment
Question by:JayMulkey
13 Comments
 
LVL 2

Accepted Solution

by:
eric_bender earned 50 total points
ID: 18042200
You can use vbscripting and write an LDAP query or you can pipe the dsquery/dsget to a file.

Let me see if I can find one.  

Do you need to iterate through differ OU's or are they all in the same place.?
0
 

Author Comment

by:JayMulkey
ID: 18042352
Eric

I'm not as AD-savvy as you (did not understand much of what you said).
I will need to iterate through different OU's.

Thanks for your help.  This could save me a TON of time!

Jay
0
 
LVL 2

Expert Comment

by:eric_bender
ID: 18042355

I use this script to give me a list of all the users & groups that exist beneath the OU in question.
As I commented this particular one writes the Group and Members (users) to a text file and each group is on one line, comma separated.
With a little modification. (do you script)  You can  tweak this one.  If not I can genericize it later.


Dim objBaseOU
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\touche.txt")

Set objBaseOU = GetObject("LDAP://OU=Touche Distribution Groups,DC=CU1,DC=ORG")

ProcessOU objBaseOU

Sub ProcessOU (ByRef objOU)
  Dim objUser, objGroup, objChildOU

  objOU.Filter = Array("user")
  WScript.Echo "Users in OU '" & objOU.Get("distinguishedName") & "':"
  For Each objUser In objOU
    WScript.Echo "  " & objUser.Get("distinguishedName")
  Next

For Each strName in arrNames
    objFile.write strpad + ","


  objOU.Filter = Array("group")
  WScript.Echo "Groups in OU '" & objOU.Get("distinguishedName") & "':"

  For Each objGroup In objOU
    WScript.Echo "  Members of group '" & objGroup.Get("distinguishedName") & "':"
    ProcessGroup objGroup, "    "
  Next

  objOU.Filter = Array("organizationalUnit")
  For Each objChildOU In objOU

    ProcessOU objChildOU
  Next
End Sub

Sub ProcessGroup (ByRef objGroup, ByVal strPad)
  Dim objMember

  For Each objMember In objGroup.Members
    If (LCase(objMember.Class) = "group") Then
      WScript.Echo strPad & objMember.Get("distinguishedName") & " (nested group)"
      ProcessGroup objMember, strPad & "  "
    Else
      WScript.Echo strPad & objMember.Get("distinguishedName")
    End If
  Next
End Sub
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:eric_bender
ID: 18042361
This does give you duplication though.  Let me work on just Iterating and sorting by OU.....
0
 
LVL 77

Assisted Solution

by:Rob Williams
Rob Williams earned 75 total points
ID: 18042386
There is a free little tool called DumpSec that will allow you to simply create reports with user account information. You can specify the information you want in the report such as user name, logon name, last time account was used, password expiries, permissions etc. These reports can be generated in different formats and can be exported as text files to import to Excel and other applications. You might want to have a look at it.
http://www.somarsoft.com/
0
 
LVL 2

Expert Comment

by:eric_bender
ID: 18042396
Ok,

So copy the script below into notepad.
You should then just need to change the entry for Set objFile to represent your text file, replace c:\touche.txt   with your location... the file does not need to exist it will be created.  
Secondly change the OU Entry (mine being Touche Distribution Groups) to the OU entry you need to use.  Then change the DC to be your domain... i.e. cu1.org relates as below.

If you have any questions let me know.


Dim objBaseOU
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\touche.txt")

Set objBaseOU = GetObject("LDAP://OU=Touche Distribution Groups,DC=CU1,DC=ORG")

ProcessOU objBaseOU

Sub ProcessOU (ByRef objOU)
  Dim objUser, objGroup, objChildOU

  objOU.Filter = Array("user")
 
  For Each objUser In objOU
      objFile.writeblanklines 1
    objFile.write " A " & objUser.Get("name")
   
  Next


  objOU.Filter = Array("group")
 

  For Each objGroup In objOU
 objFile.writeblanklines 1
    objFile.write objGroup.Get("name") + ","
   
    ProcessGroup objGroup, "    "
  Next

  objOU.Filter = Array("organizationalUnit")
  For Each objChildOU In objOU

    ProcessOU objChildOU
  Next
End Sub

Sub ProcessGroup (ByRef objGroup, ByVal strPad)
  Dim objMember

  For Each objMember In objGroup.Members
    If (LCase(objMember.Class) = "group") Then
      objFile.write strPad & objMember.Get("Name") + ","
      
    Else
      objFile.write strPad & objMember.Get("Name") + ","
      
    End If
  Next
End Sub

0
 
LVL 2

Expert Comment

by:eric_bender
ID: 18042411
Once you have made the changes save the document and rename the suffix as a .vbs  instead of the default of .txt

Then you can just double click on the it and after a short time your file will be created.

All this does is using LDAP (Lightweight Directory Addressing Protocol--AD) to retrieve the arguments accordingly.

Make sure the drive/folder exists and that you have changed the OU and Domain.  You can add additional OU= entries if you have and wish to test on a downlevel nested OU.

If you want to make the change and post it I can look at it before you run it.
0
 
LVL 2

Expert Comment

by:eric_bender
ID: 18042415
I had tried that utility in the past Rob, and for what I was trying to do it wasn't useful, but it may give Jay what he needs.
0
 
LVL 2

Expert Comment

by:eric_bender
ID: 18042428
I seem to recall that it wouldn't define the users through the nested groups.  It's been a while... I use the originally posted script to export to Excel and the post as an HTM on our Intranet for Distribution Group purposes.  
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 18046566
net user /domain > userlist.txt

or, for full names,

dsquery user "dc=yourdomain,dc=com" -name * -limit 0 | dsget user -display > userlist.txt
0
 
LVL 10

Expert Comment

by:MATTHEW_L
ID: 18053840
Shift-3 much better and easier solution.  net user /domain is the absolute easiest, but doesnt give all the info you wanted.  Also if you are using Win2003 create a saved query and export the list to excel.
0
 
LVL 2

Expert Comment

by:eric_bender
ID: 18054535
Thanx Let me know if you need any more help with the scripting.
0
 
LVL 77

Expert Comment

by:Rob Williams
ID: 18054996
Thanks JayMulkey. Good luck with it,
--Rob
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
BGP routing on Windows 2016 7 115
backup computers on Workgroup 10 80
Windows Remote Desktop Connection - changing default port. 6 63
802.1X auth setup and configuration 3 35
A brief overview to explain gateways, default gateways and static routes OR NO - you CANNOT have two default gateways on the same server, PC or other Windows-based network device. In simple terms a gateway is formed when a computer such as a serv…
Many of us in IT utilize a combination of roaming profiles and folder redirection to ensure user information carries over from one workstation to another; in my environment, it was to enable virtualization without needing a separate desktop for each…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question