Skip to Content

PowerShell - Quickly getting user logon name

To resolve an issue, a co-worker requested a list of user IDs of the affected employees. The customer just sent a list of people (first name, last name) with no user logon IDs. Using ADUC to look them all up (it was a long list) would have taken a bit of time and rather then try and have the customer revisit everyone I grabbed the lists and ran it through the command line. I had PowerShell launched and didn't want to bother with launching explorer and navigating to the directory (also, as much PowerShell as possible and practical is the game we are playing)

You will need Microsoft's PowerShell and Quests Active Directory tools installed.

Here are the steps...

This isn't a script, comments are included so I don't have to break up the formatting.
Save the user names to a file

New-Item ./users.txt -type file
notepad ./users.txt

# copy and paste the user list from (email in this case)

Get-Content PS:\temp\users.txt
$users = Get-Content PS:\temp\users.txt

# Verify the list
$users

# verify that each user is resolved to an ID
# manually prune out / correct those that don't
# the pipe feeds each line individually into the command
# the foreach acts on them one at a time
# the $_ is the placeholder for the current item
$users | foreach { Get-QADUser $_ }

# Put results in a variable so you are not continually hitting the DCs
$a = $u | foreach { Get-QADUser $_ }

# Show list of available properties
$a | gm -MemberType property

# In this case, we needed the user logon ID and displayname for the management tool.
$a | select logonname, displayname
$a | select logonname, displayname | Out-File ./list.txt