Solved

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

Posted on 2012-03-11
15
2,264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 23

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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
In-place Upgrading Dirsync to Azure AD Connect
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

729 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