This is most easily accomplished (at least I’ve found) using PowerShell. The following will do the trick:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
################## #Config Variables# ################## $strOUDN = "OU=OUName,DC=DOMAIN,DC=LOCAL" #DN of OU $strFilePath = "C:\Usernames.csv" #Path to where results will be exported ##################################### #Export all usernames from domain/OU# ##################################### Import-Module ActiveDirectory Get-ADUser -SearchBase $strOUDN -Properties samaccountname -Filter * | Export-Csv -Path $strFilePath ##################################################### #Export usernames of all disabled users in domain/OU# ##################################################### Import-Module ActiveDirectory Search-ADAccount -SearchBase $strOUDN -AccountDisabled -UsersOnly | Select -Property samaccountname | Export-Csv -Path $strFilePath |