[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Export Users list from Active Directory

Posted on 2011-10-19
6
Medium Priority
?
813 Views
Last Modified: 2012-05-12
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,
0
Comment
Question by:Impex
6 Comments
 
LVL 9

Assisted Solution

by:pritamdutt
pritamdutt earned 332 total points
ID: 36992017
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
 

Author Comment

by:Impex
ID: 36992152
I have no experience with VB. Can you please let me know how to create and run this script.
0
 
LVL 6

Accepted Solution

by:
Sid_F earned 336 total points
ID: 36992158
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
LVL 14

Assisted Solution

by:Shabarinath Ramadasan
Shabarinath Ramadasan earned 332 total points
ID: 36992172
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
 
LVL 9

Expert Comment

by:pritamdutt
ID: 36992213
Please copy the given code in a file called a.vbs
then run command cscript a.vbs

It is that easy :)


Cheers!
0
 

Author Closing Comment

by:Impex
ID: 36992477
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

Featured Post

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.

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Suggested Courses

834 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