We help IT Professionals succeed at work.

How to Generate List of Network Logins from List of User Display Names

Spike99 asked
Last Modified: 2017-06-06
I get frequent requests to retrieve the login ID for a list of users which comes in a list like this:

Smith, John
Doe, Jane
Parker, Peter
Wilson, Wade
Clooney, George
Public, John Q.

The names in the lists I get are identical to their AD display names.  Display Names in our AD are always "Last Name, First Name." Sometimes, they do include the Middle Initial ("Last Name, First Name MI").

I tried using the function I found on this page;  https://gallery.technet.microsoft.com/scriptcenter/Retrieve-a-list-of-Active-90c533a2
But, apparently the running of unsigned scripts is blocked on my network:  I am unable to set Execution Policy to unrestricted so that I can run it.
I tried creating a script myself, but I'm having no luck.

I would like to import the list of users from a TXT, CSV or XLSX file, run the operation to get the samAccountName & then output the results to TXT or CSV.

I am running this on a Windows 7 Enterprise computer with ActiveDirectory tools loaded and PowerShell v. 4.

Thanks in advance for any advice you can give.

Watch Question

Most Valuable Expert 2019
Most Valuable Expert 2018
Unlock this solution and get a sample of our free trial.
(No credit card required)
Spike99On-Site IT Technician


I tweaked it a bit by removing "DistinguishedName" because I didn't really need that, but otherwise it worked perfectly!

Thank you!
Spike99On-Site IT Technician


I found another solution to this in case anyone is  interested:

To run this, create a CSV file that has the display names in this format:
"Kirk, James T."
"Francis, Pope"
"Robinson, Jackie"
"Kenobi, Obi-Wan"

Open in new window

Then, run the PowerShell script:
Import-Module ActiveDirectory
$Sam = @()
$names = Import-csv "C:\Path\Path\FileName-In.csv"

foreach ($name in $names.displayname) 
$sam += get-aduser -filter {name -like $name} -properties samaccountname | Select Name, GivenName, SurName, samAccountName


$Sam | Export-Csv C:\Path\Path\FileName-Out.csv -NoTypeInformation

Open in new window

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.