Windwos 2003 Active Directory User List

Posted on 2010-11-18
Last Modified: 2012-05-10
Is there a way to download a list of all user accounts in the user container of active directory?  If yes, can it be done in excel?
Question by:deklinm
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
  • 2
LVL 27

Accepted Solution

KenMcF earned 250 total points
ID: 34165942
I would use ADfind -

you can add any other attributes you need.

adfind -base "OU=USERACCOUNTS,DC=DOMAIN,DC=LOCAL" -f "&(objectcategory=person)(objectclass=user)" name samaccountname mail -csv -nolabel -nodn >c:\users.csv

LVL 13

Assisted Solution

Rick earned 250 total points
ID: 34165951
LVL 13

Expert Comment

ID: 34165978
Or a vbscript, like this one:

Dim ObjWb
 Dim ObjExcel
 Dim x, zz
 Set objRoot = GetObject("LDAP://RootDSE")
 strDNC = objRoot.Get("DefaultNamingContext")
 Set objDomain = GetObject("LDAP://" & strDNC) ' Bind to the top of the Domain using LDAP using ROotDSE
 Call ExcelSetup("Sheet1") ' Sub to make Excel Document
 x = 1
 Call enummembers(objDomain)
 Sub enumMembers(objDomain)
 On Error Resume Next
 Dim Secondary(20) ' Variable to store the Array of 2ndary email alias's
 For Each objMember In objDomain ' go through the collection
 If ObjMember.Class = "user" Then ' if not User object, move on.
 x = x +1 ' counter used to increment the cells in Excel
    objwb.Cells(x, 1).Value = objMember.Class
    ' I set AD properties to variables so if needed you could do Null checks or add if/then's to this code
    ' this was done so the script could be modified easier.
 SamAccountName = ObjMember.samAccountName
 Cn = ObjMember.CN
 FirstName = objMember.GivenName
 LastName =
 initials = objMember.initials
 Descrip = objMember.description
 Office = objMember.physicalDeliveryOfficeName
 Telephone = objMember.telephonenumber
 EmailAddr = objMember.mail
 WebPage = objMember.wwwHomePage
 Addr1 = objMember.streetAddress
 City = objMember.l
 State =
 ZipCode = objMember.postalCode
 Title = ObjMember.Title
 Department = objMember.Department
 Company = objMember.Company
 Manager = ObjMember.Manager
 Profile = objMember.profilePath
 LoginScript = objMember.scriptpath
 HomeDirectory = ObjMember.HomeDirectory
 HomeDrive = ObjMember.homeDrive
 AdsPath = Objmember.Adspath
 LastLogin = objMember.LastLogin
 zz = 1 ' Counter for array of 2ndary email addresses
 For each email in ObjMember.proxyAddresses
     If Left (email,5) = "SMTP:" Then
 Primary = Mid (email,6) ' if SMTP is all caps, then it's the Primary
     ElseIf Left (email,5) = "smtp:" Then
        Secondary(zz) = Mid (email,6) ' load the list of 2ndary SMTP emails into Array.
        zz = zz + 1
     End If
 ' Write the values to Excel, using the X counter to increment the rows.
 objwb.Cells(x, 2).Value = SamAccountName
 objwb.Cells(x, 3).Value = CN
 objwb.Cells(x, 4).Value = FirstName
 objwb.Cells(x, 5).Value = LastName
 objwb.Cells(x, 6).Value = Initials
 objwb.Cells(x, 7).Value = Descrip
 objwb.Cells(x, 8).Value = Office
 objwb.Cells(x, 9).Value = Telephone
 objwb.Cells(x, 10).Value = EmailAddr
 objwb.Cells(x, 11).Value = WebPage
 objwb.Cells(x, 12).Value = Addr1
 objwb.Cells(x, 13).Value = City
 objwb.Cells(x, 14).Value = State
 objwb.Cells(x, 15).Value = ZipCode
 objwb.Cells(x, 16).Value = Title
 objwb.Cells(x, 17).Value = Department
 objwb.Cells(x, 18).Value = Company
 objwb.Cells(x, 19).Value = Manager
 objwb.Cells(x, 20).Value = Profile
 objwb.Cells(x, 21).Value = LoginScript
 objwb.Cells(x, 22).Value = HomeDirectory
 objwb.Cells(x, 23).Value = HomeDrive
 objwb.Cells(x, 24).Value = Adspath
 objwb.Cells(x, 25).Value = LastLogin
 objwb.Cells(x,26).Value = Primary
 ' Write out the Array for the 2ndary email addresses.
 For ll = 1 To 20
 objwb.Cells(x,26+ll).Value = Secondary(ll)
 ' Blank out Variables in case the next object doesn't have a value for the property
 SamAccountName = "-"
 Cn = "-"
 FirstName = "-"
 LastName = "-"
 initials = "-"
 Descrip = "-"
 Office = "-"
 Telephone = "-"
 EmailAddr = "-"
 WebPage = "-"
 Addr1 = "-"
 City = "-"
 State = "-"
 ZipCode = "-"
 Title = "-"
 Department = "-"
 Company = "-"
 Manager = "-"
 Profile = "-"
 LoginScript = "-"
 HomeDirectory = "-"
 HomeDrive = "-"
 Primary = "-"
 For ll = 1 To 20
 Secondary(ll) = "" 
    End If
    ' If the AD enumeration runs into an OU object, call the Sub again to itinerate
    If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then
        enumMembers (objMember)
    End If
 End Sub
 Sub ExcelSetup(shtName) ' This sub creates an Excel worksheet and adds Column heads to the 1st row
 Set objExcel = CreateObject("Excel.Application")
 Set objwb = objExcel.Workbooks.Add
 Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName)
 Objwb.Name = "Active Directory Users" ' name the sheet
 objExcel.Visible = True
 objwb.Cells(1, 2).Value = "SamAccountName"
 objwb.Cells(1, 3).Value = "CN"
 objwb.Cells(1, 4).Value = "FirstName"
 objwb.Cells(1, 5).Value = "LastName"
 objwb.Cells(1, 6).Value = "Initials"
 objwb.Cells(1, 7).Value = "Descrip"
 objwb.Cells(1, 8).Value = "Office"
 objwb.Cells(1, 9).Value = "Telephone"
 objwb.Cells(1, 10).Value = "Email"
 objwb.Cells(1, 11).Value = "WebPage"
 objwb.Cells(1, 12).Value = "Addr1"
 objwb.Cells(1, 13).Value = "City"
 objwb.Cells(1, 14).Value = "State"
 objwb.Cells(1, 15).Value = "ZipCode"
 objwb.Cells(1, 16).Value = "Title"
 objwb.Cells(1, 17).Value = "Department"
 objwb.Cells(1, 18).Value = "Company"
 objwb.Cells(1, 19).Value = "Manager"
 objwb.Cells(1, 20).Value = "Profile"
 objwb.Cells(1, 21).Value = "LoginScript"
 objwb.Cells(1, 22).Value = "HomeDirectory"
 objwb.Cells(1, 23).Value = "HomeDrive"
 objwb.Cells(1, 24).Value = "Adspath"
 objwb.Cells(1, 25).Value = "LastLogin"
 objwb.Cells(1, 26).Value = "Primary SMTP"
 End Sub
 MsgBox "Done" ' show that script is complete

Expert Comment

ID: 34166014
Are you looking to get a list remotely from the server?  Or can you use the Active Directory Users and Computers to export to CSV and then open in Excel that way?

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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