Export a list of all users on our domain and I am not familiar with DSQUERY or DSGET

active-directorydsquery

I am really struggling to create the query that will export the following:
Account
FirstName
LastName
the OU that the user resides in

Ideally I would like it as a CSV. I do not have access to the domain controller, but can run DSQUERY/DSGET/etc. from my pc.

Best Answer

Depending on your tools, you can do

dsquery user dc=contoso,dc=com | dsget user -samid -fn -ln -dn > names.csv 

That'll create a space-separated list of account name, firstname, lastname, and location.

Converting it into a true csv takes a bit more work.

$userList=dsquery user dc=contoso,dc=com | dsget user -samid -fn -ln -dn
foreach ($user in $userList) {
    $outstring=$user.trim(" ") -replace('\s+',',')
    write-host  `"$outstring`"
}

Which will get you output like

"samid","fn","ln","dn"
"jarey.boe","jarey","boe","cn=jarey.boe,ou=users,dc=contoso,dc=com"
Related Topic