Solved

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

Posted on 2006-11-29
13
277 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Join & Write a Comment

A common practice in small networks is making file sharing easy which works extremely well when intra-network security is not an issue. In essence, everyone, that is "Everyone", is given access to all of the shared files - often the entire C: drive …
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now