Solved

Export Users and Attributes from Active Directory on 2003

Posted on 2006-11-01
14
975 Views
Last Modified: 2009-07-29
Hello

I would like to export easily export a list of all users from Active Directory on Windows server 2003.  I tried this command NET USERS /DOMAIN >USERS.TXT  but this only exports the actual users.  But I need more information like what OU they are in and some attributes from their user profile like their profile path.

Is there a way to do this?  And export this to a file?

Thanks

Mike
0
Comment
Question by:MickaelE
  • 7
  • 3
  • 2
14 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 250 total points
ID: 17848621
You can get basic details with

dsquery USER | dsget USER -options

where -options are some of these (see these by typing dsget USER -?)

e.g.

dsget USER -ln -fn -display -acctexpires

When you are happy with it redirect to a file with >users.txt

Lotsof options with DSQUERY and DSUSER

-dn                     Shows the DN of the user.
-samid                  Shows the SAM account name of the user.
-sid                    Shows the user Security ID.
-upn                    Shows the user principal name of the user.
-fn                     Shows the first name of the user.
-mi                     Shows the middle initial of the user.
-ln                     Shows the last name of the user.
-display                Shows the display name of the user.
-empid                  Shows the user employee ID.
-desc                   Shows the description of the user.
-office                 Shows the office location of the user.
-tel                    Shows the telephone number of the user.
-email                  Shows the e-mail address of the user.
-hometel                Shows the home telephone number of the user.
-pager                  Shows the pager number of the user.
-mobile                 Shows the mobile phone number of the user.
-fax                    Shows the fax number of the user.
-iptel                  Shows the user IP phone number.
-webpg                  Shows the user web page URL.
-title                  Shows the title of the user.
-dept                   Shows the department of the user.
-company                Shows the company info of the user.
-mgr                    Shows the user's manager.
-hmdir                  Shows the user home directory.
                        Displays the drive letter to which the
                        home directory of the user is mapped
                        (if the home directory path is a UNC path).
-hmdrv                  Shows the user's home drive letter
                        (if home directory is a UNC path).
-profile                Shows the user's profile path.
-loscr                  Shows the user's logon script path.
-mustchpwd              Shows if the user must change his/her password
                        at the time of next logon. Displays: yes or no.
-canchpwd               Shows if the user can change his/her password.
                        Displays: yes or no.
-pwdneverexpires        Shows if the user password never expires.
                        Displays: yes or no.
-disabled               Shows if the user account is disabled
                        for logon or not. Displays: yes or no.
-acctexpires            Shows when the user account expires.
                        Display values: a date when the account expires
                        or the string "never" if the account never expires.
-reversiblepwd          Shows if the user password is allowed to be
                        stored using reversible encryption (yes or no).
<UserDN>                Required. DN of group to view.
-memberof               Displays the groups of which the user is a member.
0
 
LVL 10

Expert Comment

by:SeanUK777
ID: 17848886
dont forget to pipe to either a text (.txt) or excel (.xls) file by adding the following after the commands listed above..


 > c:\user.txt

or

 > c:\users.xls
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17849589
As I said above :-)  Exporting text to an XLS will work but it isn't a true XLS file just a text file called .XLS.  You could as easily open the text file in Excel if needed.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:MickaelE
ID: 17849936
How long should this take to run.  I ran dsget USER -ln -fn -display -acctexpires and it is taking ages?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17849964
How many users are we talking about.  It will dump all the users into a temporary file effectively then pipe that into dsget USER.  Did you run it as shown:

dsquery USER |dsget USER -ln -fn -display -acctexpires

Otherwise yes it will just sit there... actually looks like I didn't post the first bit into the second example, sorry!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17849970
You can of course limit it to certain OU downward etc. too if needed with paramaters on the dsquery command.
0
 

Author Comment

by:MickaelE
ID: 17850100
this is what I did.  I used the second example.  What is the switch for OU?  I did not see it in the list.

Mike
0
 

Author Comment

by:MickaelE
ID: 17850115
I am trying to output 200 users.  What is the syntax for that it seems to limit at 100.

Thanks

0
 
LVL 10

Assisted Solution

by:SeanUK777
SeanUK777 earned 250 total points
ID: 17850128
c:\>dsquery user -limit 0 | dsget user -ln -fn -acctexpires > c:\users.txt

or

c:\>dsquery user -limit 0 | dsget user -ln -fn -acctexpires > c:\users.xls
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17850132
Have a look at dsquery -? for the OU syntax, sorry not on a machine I can check it for myself at the moment but think you just specify, i.e.

DSQUERY OU=x.DC=yourdomain.DC=com USER ..... but check it please!

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17850144
Just checked on a different machine, to unlimit the output use

dsquery user -limit n

if you make n it is umlimited or make it 500 or whatever.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 17850165
Oops, didn't see your post in the middle SeanUK...

I had the syntax back to front for selecting an OU too:

dsquery USER ou=x,DC=x,DC=com | dsget user  ...

Steve
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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