Export Users list from Active Directory

Hi Experts,

Can you please let me know the way to export the users list for the domain test.com. 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,
ImpexAsked:
Who is Participating?
 
pritamduttCommented:
Please find below the vbscript code for same

Regards,
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 
NEXT 
 
objSheet.Range("A2").CopyFromRecordset(rs) 
objWB.SaveAs(strExportFile) 
 
 
rs.close 
cn.close 
SET objSheet = NOTHING 
SET objWB =  NOTHING 
objExcel.Quit() 
SET objExcel = NOTHING 
 
Wscript.echo "Script Finished..Please See " & strExportFile

Open in new window

0
 
ImpexAuthor Commented:
I have no experience with VB. Can you please let me know how to create and run this script.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
Shabarinath RamadasanInfrastructure ArchitectCommented:
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.

http://www.quest.com/powershell/activeroles-server.aspx

Good luck
Shaba
0
 
pritamduttCommented:
Please copy the given code in a file called a.vbs
then run command cscript a.vbs

It is that easy :)


Cheers!
0
 
ImpexAuthor Commented:
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,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.