Solved

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

Posted on 2006-11-29
13
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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 …
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

628 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