Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2377
  • Last Modified:

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

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
rdefino
Asked:
rdefino
1 Solution
 
Mike KlineCommented:
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
 
yo_beeDirector of ITCommented:
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
 
X_layerCommented:
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
Problems using Powershell and Active Directory?

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

 
micropc1Commented:
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
 
rdefinoAuthor Commented:
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
 
X_layerCommented:
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
 
rdefinoAuthor Commented:
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
 
X_layerCommented:
Yeah, you must replace "DC=mydomain,DC=com" with correct informations of your domain.
0
 
rdefinoAuthor Commented:
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
 
X_layerCommented:
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
 
rdefinoAuthor Commented:
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
 
X_layerCommented:
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
 
rdefinoAuthor Commented:
I tried that, but it didn't pull any mail address.
0
 
X_layerCommented:
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
 
rdefinoAuthor Commented:
worked like a charm!
0

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now