One of my customers asked for an overview of the UPNs of all users in a specific OU. Having become fairly familiar with the Get-ADUser command, I decided to see if I couldn’t make it do this, too.
I knew that I would need to filter the results of the command on OU, and found that the -filter
parameter, combined with -SearchBase
would give me what I wanted. To this end, I ran the following command:
Get-ADUser -Filter * -SearchBase “ou=ouname,dc=company,dc=com”
That, however, did not give me the result I was looking for. For that, I needed to pipe the results through a second command to get the UPN, and then a third to select it and output it to a file.
Get-ADUser -Filter * -SearchBase “ou=ouname,dc=company,dc=com” | Get-ADUser -property UserPrincipalName | select UserPrincipalName > results.txt
By posting a comment, you consent to our collecting the information you enter. See privacy policy for more information.