0

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.

David Kehoe
  • 23
  • 1
  • 5
  • Have you tried anything? You may want to have a look at the [tour] and [help], to learn how questions should be asked on SO. – Burki Jan 28 '16 at 14:37

2 Answers2

1

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)'
Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62
1

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" }
Gabriel Luci
  • 38,328
  • 4
  • 55
  • 84
  • This doesn't give me any output unfortunately. Ran in Administrator mode. – David Kehoe Jan 28 '16 at 19:39
  • What you put in quotes must match exactly to the "cn" attribute of the user. Also, is the user account that you are looking for on the same domain that you are logged into? – Gabriel Luci Jan 28 '16 at 19:52
  • Thank you, so the part in quotes was wrong, because the format we have been using is "Doe, John". Thank you for your help. – David Kehoe Jan 28 '16 at 20:56