Export AD Users to csv file

Roger Roger 7,181 Reputation points
2021-01-21T12:56:01.637+00:00

Hi Experts

i have a OU i want to pull all the users in that OU to csv file, can anyone help me with the syntax. i want to try the below syntax will it work

Get-ADUser -Filter * -SearchBase "OU=MYOU,OU=TopLevelOU,DC=contoso,DC=com" -Properties * | Select-Object Displayname,Description,userprincipalname,samaccountname,LastLogin | Export-csv C:\output.csv -NoTypeInformation

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
Windows for business Windows Server User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. Mohamed El-Qassas 1,401 Reputation points MVP Volunteer Moderator
    2021-01-21T13:15:54.753+00:00

    The below PowerShell command should work

    Get-ADUser -Filter * -SearchBase "OU=Research,OU=Users,DC=ad,DC=contoso,DC=com" -Properties * | Select-Object name | export-csv -path c:\temp\userexport.csv  
    

    You can also do the same task using AD GUI

    • Open AD, Click on Filter Button.

    59114-filter.jpg

    • Perform a Custom filter for Organization Unit.

    59211-ad1.png

    • Click on the Export button

    59212-export.jpg

    • Select CSV file extension

    59185-csv.jpg

    6 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. SUNOJ KUMAR YELURU 15,256 Reputation points MVP Volunteer Moderator
    2021-01-21T13:13:07.577+00:00

    Hi @Roger Roger

    Something like this:

    If you have a big AD, that might take a while though.

    Import-Module ActiveDirectory
    Get-ADUser -Filter * -Properties * | export-csv c:\ADusers.csv

    Export users from Active Directory using PowerShell
    There is another, much quicker way to accomplish the title task. You can export users from Active Directory using PowerShell. The cmdlet below exports a complete list of my company’s users to a csv file.

    Get-ADUser -Filter 'Company -like "Alpha*"' -Properties * | Select -Property EmailAddress,GivenName,Surname,DisplayName,Title,Department,Office,OfficePhone,MobilePhone,Fax,StreetAddress,City,State,PostalCode,Country | Export-CSV "C:\\ADusers.csv" -NoTypeInformation -Encoding UTF8

    Powershell Script to export Active Directory users to CSV

    Please don’t forget to Accept the answer and up-vote wherever the information provided helps you, this can be beneficial to other community members.

    7 people found this answer helpful.
    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.