Exporting a .csv of users out of Active Directory

Even though I found many tutorials on how to export Active Directory users from a group into a comma-separated values text file, none did exactly what I wanted (specify an organizational unit, get only the active users, get the first and last name and the email address out).

I had to do a little bit of trial and error (I'm not a PowerShell guru), but I ended up with this for a working PowerShell command:

get-aduser -searchbase "ou=organizationalunit,ou=organizationalunit,dc=domaincomponent,dc=domaincomponent" -filter 'enabled -eq $true' -properties department| select-object name,department,givenName,surname,userPrincipalName | export-csv c:\Users\username\Desktop\temp.csv

I believe there is an actual email or emailaddress or windowsemailaddress attribute, but the one, at least for our system, that gave me a usable email address (and not gobbledygook) was userPrincipalName. Your mileage may vary.

Leave a Reply

Your email address will not be published. Required fields are marked *