What are you using to try and get the SamAccountName attribute? You should be able to use Import-Csv to get the list of display names from your file, and then you can use Get-ADUser with the -filter parameter to pull the data from AD.
Assuming the display name column of the CSV is DisplayName and that column contains the actual display names from AD:
$names = Import-Csv c:\temp\displaynames.txt
foreach ($name in $names) {
$user = Get-ADUser -filter { Name -like $name.DisplayName }
$user.SamAccountName
}
Can I see an example of your CSV file, with the header, and then see what happens at the console when you run my code snippet? Also, if you run “$names = Import-Csv C:\Displaynames.csv”, then running “$names” should show you the imported names and the column headers that it’s using. Can you show me an example of that output?
FullyQualifiedErrorId : Property: ‘DisplayName’ not found in object of type: ‘System.Management.Automation.PSCustomObject’.,Microsoft.ActiveDirectory.Management.Commands.GetADUser
Could be used inside a ForEach to take values from your CSV. -Identity only takes samAccountName, CN, and a couple of other specific things that are indexed in the database.