Solved

How can I query to get all users id's and full names from AD

Posted on 2012-03-11
15
2,113 Views
Last Modified: 2012-03-13
I need to get all of my users ID's and their full names from AD. Also, their email addresses would be good to.

We are running a 2003 AD structure.

how can I get these outputted to an excel file?

What is the syntax for this?
0
Comment
Question by:rdefino
15 Comments
 
LVL 57

Expert Comment

by:Mike Kline
ID: 37706946
Lots of ways

adfind is one way  http://www.joeware.net/freetools/tools/adfind/index.htm

adfind -default -f "&(objectcategory=person)(objectclass=user)" samaccountname givenname sn mail -nodn -csv > c:\users.csv

If you prefer a GUI tool adinfo is a nice free tool   http://www.cjwdev.co.uk/Software/ADReportingTool/Info.html

In addition powershell, csvde, dstools are other ways.

Thanks

Mike
0
 
LVL 21

Expert Comment

by:yo_bee
ID: 37706959
when you say ID do you mean their logon id?

There are a few ways.
utilities:
CSVDE or DSQUERY
Or
use VBS or POWERSHELL.

csvde -f output.csv -d "dc=domain,dc=com" -r "(objectClass=user)" -l "displayName,mail,,sAMAccountName"

dsquery User "dc=domain,dc=com" -limit 0 | DSGET User -display -email -samid >output.txt

The later two are more difficult to put together.
I will elaborate later if needed,but try the first two and see if that works.
0
 
LVL 11

Expert Comment

by:X_layer
ID: 37707027
And also Powershell script. First will output data on screen:
Get-ADUser -Filter * -Properties * | ft SamAccountName,Surname,GivenName,mail

Open in new window

Second will export data in CSV file:
Get-ADUser -Filter * -Properties * | select SamAccountName,Surname,GivenName,mail | Export-Csv c:\Users.csv

Open in new window

0
 
LVL 7

Expert Comment

by:micropc1
ID: 37707034
Use the built-in query capabilities of the AD Users and Computers mmc snap-in. It will also let you export to a csv.
0
 

Author Comment

by:rdefino
ID: 37707142
x_layer,

the 2nd one seemed to work great. One thing, how can I have this look under a particular OU. say: usersaccount\people?
0
 
LVL 11

Expert Comment

by:X_layer
ID: 37707171
You can try like this:
Get-ADUser -Filter * -SearchBase "OU=People,OU=UserAccount,DC=mydomain,DC=com" | select SamAccountName,Surname,GivenName,mail | Export-Csv c:\Users.csv
0
 

Author Comment

by:rdefino
ID: 37707223
so that give me an error:

Get-ADUser : The supplied distinguishedName must belong to one of the following partition(s): 'CN=Configuration,DC=dr,D
C=xxxxxxx,DC=com , CN=Schema,CN=Configuration,DC=dr,DC=xxxxxxx,DC=com , DC=global,DC=xxxxxx,DC=com , DC=DomainDnsZones
,DC=global,DC=xxxxxx,DC=com , DC=ForestDnsZones,DC=dr,DC=xxxxxxx,DC=com'.
At line:1 char:11
+ Get-ADUser <<<<  -Filter * -SearchBase "OU=People,OU=UserAccounts,DC=mydomain,DC=com" | select SamAccountName,Surname
,GivenName,mail | Export-Csv c:\Users.csv
0
 
LVL 11

Expert Comment

by:X_layer
ID: 37707229
Yeah, you must replace "DC=mydomain,DC=com" with correct informations of your domain.
0
 

Author Comment

by:rdefino
ID: 37707264
I been trying that, in all different ways, but still not working. I must be entering it in wrong.

Say the name of my AD structure is world.mustang.com

How would that be used in the syntax.

Also, my accounts are kept in OU:  useraccounts\people

thanks
0
 
LVL 11

Expert Comment

by:X_layer
ID: 37707285
Then it should be:
Get-ADUser -Filter * -SearchBase "OU=People,OU=UserAccounts,DC=world,DC=mustang,DC=com" | select SamAccountName,Surname,GivenName,mail | Export-Csv c:\Users.csv

Open in new window

0
 

Author Comment

by:rdefino
ID: 37707306
that work much better.

On thing and I'm all set. How can I get it to give me the email address to.

there is the mail column, but no email addresses.

thanks
0
 
LVL 11

Expert Comment

by:X_layer
ID: 37707321
Then you change it. Maybe this will give you what you need:
Get-ADUser -Filter * -SearchBase "OU=People,OU=UserAccounts,DC=world,DC=mustang,DC=com" | select SamAccountName,Surname,GivenName,EmailAddress | Export-Csv c:\Users.csv

Open in new window

0
 

Author Comment

by:rdefino
ID: 37707331
I tried that, but it didn't pull any mail address.
0
 
LVL 11

Accepted Solution

by:
X_layer earned 500 total points
ID: 37708506
Sorry, my fault. This should pull email addresses too:
Get-ADUser -Filter * -SearchBase "OU=People,OU=UserAccounts,DC=world,DC=mustang,DC=com" -Properties * | select SamAccountName,Surname,GivenName,EmailAddress | Export-Csv c:\Users.csv

Open in new window

0
 

Author Closing Comment

by:rdefino
ID: 37714563
worked like a charm!
0

Join & Write a Comment

Do you have users whose passwords are expiring and they are constantly calling you?  Well I sure did and needed a way to put an end to this.  We have a lot of remote users which would not be notified that their passwords were expiring since they wer…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now