Powershell Search for AD Users

1.2k views Asked by At

I am learning Powershell and use it frequently for adding users to AD Groups. I would like to know if it is possible to search for AD Usernames using the persons common name (i.e. John Doe = JDoe). It is very time consuming and defeats the purpose of using Powershell if I have to use AD Users and Computers to look up their UID every time.

UPDATE: I tried the Get-ADUser -filter { cn -eq 'John Doe' } and Get-ADUser -filter { Name -eq 'John Doe' } command and I did not receive any output from the console, it immediately went to the next line.

I also have RSAT installed, just to clarify. I have looked at the technet article on MS' page Get-ADUser to try and figure it out before I posted the OP.

Just to clarify I am looking to search by the Common Name to find that user's Login Name. i.e. Searching 'John Doe' to find 'jdoe' the User Logon Name.

2

There are 2 answers

3
Gabriel Luci On BEST ANSWER

Yes. You need to install RSAT. See here for instructions for various Windows versions.

Then use Get-ADUser:

Get-ADUser -filter { cn -eq "Common Name" }
2
Bill_Stewart On

I'm not sure what your specific question is, but you can use the AD cmdlets to search using ambiguous name resolution (ANR):

Get-ADUser -LDAPFilter '(anr=jdoe)'

See https://support.microsoft.com/en-us/kb/243299 for more information about ANR.

To search by the cn attribute only, just change the LDAP filter:

Get-ADUser -LDAPFilter '(cn=John Doe)'