Exporting users and email addresses

I need to query AD to show the user and the users email address.  How can I accomplish this?
WellingtonISAsked:
Who is Participating?
 
Dustin SaundersConnect With a Mentor Director of OperationsCommented:
In the -Filter section you can specify criteria.
Get-ADUser -Filter {SamAccountName -like "wrm*"} -Properties EmailAddress | Select-Object Name,EmailAddress | Export-Csv -Path "C:\path\to\export\users.csv" -NoTypeInformation

Open in new window


If you want to get all users from a specific location, use -SearchBase
Get-ADUser -SearchBase "OU=Test,DC=domain,DC=local" -Filter * -Properties EmailAddress | Select-Object Name,EmailAddress | Export-Csv -Path "C:\path\to\export\users.csv" -NoTypeInformation

Open in new window


Just edit the DN for the starting location.  Or you can use the first one.
0
 
Dustin SaundersDirector of OperationsCommented:
Just an FYI, if you add in the scripting language those Experts will be able to see your question easier.

This code pulls alist of AD users and their Email Address.
Get-ADUser -Filter * -Properties EmailAddress | Select-Object Name,EmailAddress

Open in new window

0
 
WellingtonISAuthor Commented:
Powershell?  Can this be set to export to CSV or XLSX? For the filter put in the OU?
0
Improved Protection from Phishing Attacks

WatchGuard DNSWatch reduces malware infections by detecting and blocking malicious DNS requests, improving your ability to protect employees from phishing attacks. Learn more about our newest service included in Total Security Suite today!

 
Dustin SaundersDirector of OperationsCommented:
Yes-- Powershell is incredibly powerful for AD management.  Edit the -Path to where you want the file to export.
Get-ADUser -Filter * -Properties EmailAddress | Select-Object Name,EmailAddress | Export-Csv -Path "C:\path\to\export\users.csv" -NoTypeInformation

Open in new window

0
 
WellingtonISAuthor Commented:
That worked however, I'm in a huge domain with an OU that is mine  Can I add the DN so I don't get the entire list of users?  Or even better the user name begins with wrm if I can user that.
0
 
WellingtonISAuthor Commented:
Thanks!  that worked great!
0
 
Dustin SaundersDirector of OperationsCommented:
No problem, glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.