Export AD Users to csv file

Roger Roger 4,956 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 Server 2016
Windows Server 2016
A Microsoft server operating system that supports enterprise-level management updated to data storage.
2,388 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,205 questions
Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,932 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} vote

Accepted answer
  1. Mohamed El-Qassas 1,391 Reputation points MVP
    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

    4 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. SUNOJ KUMAR YELURU 13,946 Reputation points MVP
    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.

    5 people found this answer helpful.
    0 comments No comments

  2. Samdi 26 Reputation points
    2021-08-21T05:14:24.637+00:00

    This helped me:

    https://www.alitajran.com/export-ad-users-to-csv-powershell/

    You can fill in the OU or OUs or whole AD (all users)

    1 person found this answer helpful.
    0 comments No comments