PowerShell – Return AD Users and Last OU

email me

Get-ADUser -Filter * -SearchBase "dc=YourDomain,dc=com" | select Name, @{l='OU';e={$_.DistinguishedName.split(',')[1].split('=')[1]}}

 

Notes

Get-ADUser

 

# Return users and full distinguished names
Get-ADUser -Filter * -SearchBase "dc=YourDomain,dc=com" | select Name, DistinguishedName

 

tags: MrNetTek