Export Ad User to CSV in PowerShell

Active directory user has many attributes associated with it to describe ad user. As an administrator, often we export ad user to csv file to go through user attributes, analyze aduser attributes, prepare aduser report and so on.

Get-AdUser cmdlet in active directory get one or more users from active directory based on search criteria and using filter conditions get ad users from domain, specific OU. Using Export-Csv to export ad users to csv file with all attributes in PowerShell.

In this article, I will explain how to use Get-AdUser to export users from active directory to csv file, export ad users email address from active directory with examples.

Export Ad Users Name to CSV

To export aduser name to csv file, use Get-AdUser cmdlet in active directory with Filter parameter as below

Get-ADUser -Filter * | Select-Object Name | export-csv -path D:\adusers-export.csv -NoTypeInformation

In the above PowerShell script, Get-AdUser get all users in domain using Filter * ( wildcard character ) and using Export-Csv, it export aduser name to csv file.

Export AdUser Email Addresses from Active Directory to Csv

Active directory user has email address attribute, to export aduser email addresses from active directory to csv file, use Get-AdUser cmdlet as below

Get-ADUser -Filter * -Properties * | Select Name, EMailAddress,DisplayName | Export-Csv D:\adusers-export.csv -NoTypeInformation

In the above PowerShell script, It get ad users from active directory and pass it to second command through pipe operator (|)

Second command uses Name, DisplayName, EmailAddress to export aduser email address from active directory to csv file.

Above script, export ad user multiple attributes to csv file.

Export Users from Active Directory OU to CSV

Organizational Unit (OU) is a container in Active directory contains user, computers and groups. To export users from active directory OU to csv file, use Get-AdUser cmdlet as below

Get-ADUser -Filter * -SearchBase "OU=HR,DC=SHELLPRO,DC=LOCAL" -Properties * | Select Name,EMailAddress,DisplayName | Export-Csv -Path D:\adusers-export.csv -NoTypeInformation

In the above PowerShell script,

first command get aduser from active directory OU (organizational unit) using SearchBase parameter. Output of first command as below

Get AdUser from OU
Get Active Directory Users from OU

Using Export-Csv cmdlet in PowerShell, it export users from active directory OU to csv file.

Export Enabled Ad Users to CSV

Active directory user Enabled property has either True or False value which decide aduser is enabled or not.

To export enabled ad users to csv file, use Get-AdUser cmdlet as below

Get-ADUser -Filter * -Property * | Where-Object {$_.Enabled -like "True"} | Select Name, EmailAddress, DisplayName | Export-Csv -Path D:\adusers-export.csv -NoTypeInformation

In the above PowerShell script,

First command get adusers from active directory and pass user objects to second command.

Second command check Enabled status and select Name, EmailAddress and DisplayName.

Using Export-Csv cmdlet in PowerShell, it export enabled ad users to csv file.

Export User logon Name from Active Directory

To export user logon name, lastlogondate from active directory, use Get-AdUser cmdlet as below

 Get-ADUser -Filter * -Property * | Where-Object {$_.Enabled -like "False"} | Select Name, EmailAddress, DisplayName,LastLogonDate,UserPrincipalName | Export-Csv -Path D:\adusers-export.csv -NoTypeInformation

Above PowerShell script, get ad user name, emailaddress, displayname, lastlogondate and userprincipalname and export user logon name and last logon date to CSV file using Export-CSV.

Conclusion

I hope above article to export ad user to csv file with attribute like name, email address, logon name, last logon date helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Leave a Comment