Solved

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

Posted on 2012-03-11
15
2,174 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 22

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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This article runs through the process of deploying a single EXE application selectively to a group of user.
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 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 …

776 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