It’s unbelievable how long it took me to figure out this simple Powershell script, but yet it does the trick :).
Often you receive a request to do a certain action with a bunch of accounts, and (obviously) the list provided contains the full names rather usernames. Pain to do it manually, but yet we can utiliseย Powershell here.
What you need: CSV file, with only one column, and the header of the columnย must be called “Name”, if you prefer to use something different, simply amend Name in line 6 to reflect your header.
So what the actual script does:
Line 3 = creates variable called $listย and tells it to import a CSV file inย C:\temp\names.csv path.
Line 5 = creates a loop which will go through all records in from the CSV file
Line 6 = We retrieve usernames, filtered by their Full Name (Name in AD object property) and tell it should search underย Name header.
This is it, a few lines of code which will probably save you plenty of time in search of usernames :).
#Finds username based on full name. Header in CSV file is Name. $list = Import-Csv C:\temp\names.csv foreach ($i in $list) { Get-ADUser -Filter "Name -like '$($i.Name)'" }