Sunday, November 6, 2011

How to export user attributes to a file in active directory

To export user attributes to a file in AD we need dsquery.exe & dsget.exe

dsquery.exe command to pipe the results to a dsget.exe command.

dsquery.exe returns objects based on defined search criteria such as an OU, a domain, common name containing... , etc.

dsget.exe in turn takes the objects and reports on attributes within the object. Email address being one of the many attributes defined for user objects in a standard AD schema.



In my case I want to export the profile path, home directory and drive letter of my users

dsquery user "DC=tmk,DC=com" -limit 999 | dsget user -samid -Email -hmdir -hmdrv -profile > c:\mytextfile.txt

dsquery user, dsget user = to get user objects

"DC=tmk,DC=com" = your AD base DN to include all the user objects. You can narrow down by specifying OU, Groups…

-limit 999 = by default dsquery.exe export first 100 results only so you have to specify a limit that you can get all the users (my value is 999 because I have less than 999 users in my domain)

-samid -Email -hmdir -hmdrv –profile = AD user attributes. For full list please refer this post…

-samid = user’s login name

- Email = user’s primary email address

-hmdir = user’s home directory

-hmdrv = user’s home directory’s drive letter

-profile = user’s roaming profile path

c:\mytextfile.txt = output will be stored in this file as space separated values so you can import it to excel to get a clean view.

Build your query according to your requirements and paste it in command prompt and hit enter…

No comments:

Post a Comment