Export Users list from Active Directory

Posted on 2011-10-19
Last Modified: 2012-05-12
Hi Experts,

Can you please let me know the way to export the users list for the domain The domain has got multiple OUs and I need get the information from all the OUs and exported to an excel or CSV file.

The information should contain Username/Full Name/ Job Title.

Many Thanks,
Question by:Impex
    LVL 9

    Assisted Solution

    Please find below the vbscript code for same

    SET objRootDSE = GETOBJECT("LDAP://RootDSE") 
    strExportFile = "C:\temp\MyExport.xls"  
    strRoot = objRootDSE.GET("DefaultNamingContext") 
    strfilter = "(&(objectCategory=Person)(objectClass=User))" 
    strAttributes = "sAMAccountName,userPrincipalName," & _ 
                                    "displayName," & _ 
                                    "title" & _ 
    strScope = "subtree" 
    SET cn = CREATEOBJECT("ADODB.Connection") 
    SET cmd = CREATEOBJECT("ADODB.Command") 
    cn.Provider = "ADsDSOObject" 
    cn.Open "Active Directory Provider" 
    cmd.ActiveConnection = cn 
    cmd.Properties("Page Size") = 1000 
    cmd.commandtext = "<LDAP://" & strRoot & ">;" & strFilter & ";" & _ 
                                       strAttributes & ";" & strScope 
    SET rs = cmd.EXECUTE 
    SET objExcel = CREATEOBJECT("Excel.Application") 
    SET objWB = objExcel.Workbooks.Add 
    SET objSheet = objWB.Worksheets(1) 
    FOR i = 0 To rs.Fields.Count - 1 
                    objSheet.Cells(1, i + 1).Value = rs.Fields(i).Name 
                    objSheet.Cells(1, i + 1).Font.Bold = TRUE 
    SET objSheet = NOTHING 
    SET objWB =  NOTHING 
    SET objExcel = NOTHING 
    Wscript.echo "Script Finished..Please See " & strExportFile

    Open in new window


    Author Comment

    I have no experience with VB. Can you please let me know how to create and run this script.
    LVL 5

    Accepted Solution

    LVL 14

    Assisted Solution

    by:Shabarinath Ramadasan
    I would suggest you try try the quest AD command lets for powershell.
    You can achive this use the below one liner.

    Get-QADUser -SizeLimit 0 -IncludeAllProperties |select samaccountname, displayname, Title |export-csv users.csv

    You need to have quest ad command lets installed form the desktop you are running this command.

    Good luck
    LVL 9

    Expert Comment

    Please copy the given code in a file called a.vbs
    then run command cscript a.vbs

    It is that easy :)


    Author Closing Comment

    Thank everyone for all the information. I did this by creating a new query from DSA.MSC but all of you gave me the right answer.

    Many Thanks,

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
    Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
    This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
    This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

    731 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

    15 Experts available now in Live!

    Get 1:1 Help Now