I'm trying to get a list of AD user's logon names from a list of display names using this script.
Import-Csv 'C:\temp\displaynames.csv'
ForEach-Object {
$name = $_.displayname
Get-ADUser -Filter * -Properties DisplayName | Where-Object {$_.displayname -eq $name}
} |
Select-Object SamAccountName, DisplayName |
Export-Csv 'C:\Temp\Results.csv' -NoType
The script appears to run without errors but I only get results for display names without spaces in them. Could it be that I need to specify more information such as the domain name? Flailing that could this be down to the formatting of my displaynames.csv list?
So far I have tried:
- A list with the names on each row (no double quotes or quotes)
- each name encapsulated by ' ' (i.e. 'Joe Bloggs')
- Each name encapsulated by " " (i.e. "Joe Bloggs")
All with the same result.