Powershell: "adsi" - look up user id given a full name? [closed]
I have a list of team members names - in a first_name, last_name format in a CSV. How can I look up their names in AD using Powershell - so that I can get their domain userids ?
I saw examples where "adsi" was used to look based on domain userid->full-name, but I need to perform this the other way round.
(For instance: Retrieve current domain user's full name)
I'm not admin on the domain - just a regular user - and want to avoid installing the Active Directory Libraries if possible (since I would like to share the script with other colleagues also - need minimum pre-reqs)
Assuming the User Account property DisplayName is "Firstname Lastname" then the following will do what you're looking for
$name = "John Doe"
$search = [adsisearcher]"(&(objectCategory=person)(objectClass=User)(displayname=$name))"
$search.FindAll() | Select-Object -ExpandProperty Properties
Note the userid is known as samAccountName