Avatar of rdefino
rdefino
Flag for United States of America asked on

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?
Active DirectoryWindows Server 2003

Avatar of undefined
Last Comment
rdefino

8/22/2022 - Mon
Mike Kline

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
yo_bee

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.
X_layer

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

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Chris Ashcraft

Use the built-in query capabilities of the AD Users and Computers mmc snap-in. It will also let you export to a csv.
rdefino

ASKER
x_layer,

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

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
rdefino

ASKER
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
X_layer

Yeah, you must replace "DC=mydomain,DC=com" with correct informations of your domain.
rdefino

ASKER
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
X_layer

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

rdefino

ASKER
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
X_layer

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
rdefino

ASKER
I tried that, but it didn't pull any mail address.
ASKER CERTIFIED SOLUTION
X_layer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rdefino

ASKER
worked like a charm!