Avatar of Spike99
Spike99Flag for United States of America

asked on 

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

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.

Alicia
PowershellActive Directory

Avatar of undefined
Last Comment
Spike99
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Spike99
Spike99
Flag of United States of America image

ASKER

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

Thank you!
Avatar of Spike99
Spike99
Flag of United States of America image

ASKER

I found another solution to this in case anyone is  interested:
https://www.reddit.com/r/PowerShell/comments/2em7ry/getting_samaccountname_from_list_of_display_names/

To run this, create a CSV file that has the display names in this format:
DisplayName
"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

Active Directory
Active Directory

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.

86K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo