Some time ago, I needed to look up the account names of a handful of users in Active Directory. The information I had beforehand was their names. I did not have ADUC available to me, but I did have PowerShell. This is an excellent use case for the Get-ADUser
cmdlet when combined with the -Filter
parameter. Here’s what my first stab at the problem looked like this:
Get-ADUser - Filter displayName "Givenname Surname"
That, however, threw an error message:
I next added a comparison operator to my command, as follows:
Get-ADUser -Filter displayName -like "Firstname Surname"
This, too, threw an error message:
Once I added curly brackets to the command, however, did get the result I wanted – although not for all the users. Whenever it didn’t find a user, it didn’t return a result. On a hunch that it might be down to spelling inconsistencies, I removed everything but their surname, and added a wildcard, which finally netted me all the users’ account names. Here is my final query:
Get-ADUser -Filter {displayName -like "*Surname"}
By posting a comment, you consent to our collecting the information you enter. See privacy policy for more information.