Export AD users information

idajagne
idajagne used Ask the Experts™
on
Hi,

I am trying to export AD user information and would like to just pull out user properties such as full name, logon account, email and discrption to a csv file. Currently, I am trying with dsquery and ldifde and below are the commands:

LDIFDE  -l "givenname,sn,displayName,sAMAccountName,memberof" -r "objectclass=user"  -f "filename.txt"

dsquery user -samid * -limit 0 | dsget user -ln -fn -office -desc -email -tel -fax -mobile -title -company

Your help is appreciated...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013
Commented:
Another great tool for this is adfind by MVP Joe Richards
http://www.joeware.net/freetools/tools/adfind/index.htm 
adfind -default -f "&(objectcategory=person)(objectclass=user)" samaccountname givenname sn description mail -nodn -csv > C:\Users.csv
That will give you the CSV file on your C drive.  Notice you how I just listed the attributes at the end...that is your output and you can add or remove attributes as you need.
 
Thanks
Mike
Here's a VBScript that you can use.  Cut-n-paste into a Text file with a .vbs extension.  Make sure you change the 'strLogFile' path and MYDOMAIN.

Let me know if you want additional attributes added.
Const ADS_SCOPE_SUBTREE = 2
strLogFile = "c:\test\User Attribs.csv"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objLogFile = objfso.CreateTextFile(strLogFile, True)

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
    "Select Name,givenname,sn,displayname,samaccountname from 'LDAP://DC=MYDOMAIN,DC=com' " _
        & "Where objectCategory ='user'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
	
'	On Error Resume Next
'    For Each sDescription In objRecordSet.Fields("description").Value
'    	WScript.Echo "Description: " & sDescription
'	Next
    objlogfile.WriteLine(objRecordSet.Fields("name").Value & "," & objRecordSet.Fields("givenname").Value & "," & objRecordSet.Fields("sn").Value & "," & objRecordSet.Fields("displayName").Value & "," & objRecordSet.Fields("sAMAccountName").Value)
'    On Error Goto 0
    objRecordSet.MoveNext
Loop

Open in new window

Author

Commented:
That did the trick! Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial