Productivv

IT | CLOUD | RELIABLE

Powershell: Export users from AD to Excel

Export all users from AD from a specific OU (recursive) to Excel

$OU = 'OU=USERS,DC=PRODUCTIVV,DC=LOCAL'
Get-ADUser -Filter * -SearchBase $OU -SearchScope Subtree | Select-object DistinguishedName,Name,UserPrincipalName | export-csv -path c:\temp\userexport.csv

Only enabled users

$OU = 'OU=USERS,DC=PRODUCTIVV,DC=LOCAL'
Get-ADUser -Filter * -SearchBase $OU -SearchScope Subtree | Select-object DistinguishedName,Name,UserPrincipalName,Enabled | Where {$_.Enabled -like "False"} | export-csv -path c:\temp\userexport.csv