When trying to search AD by a list of first and last names and output their usernames, I'm running the following script and receving an error. I replaced the $_.last and $_.first with a username to make sure the rest of the script was functional. My only problem is when I use my CSV file. The Csv file looks like this....
Last,FirstSmith,John
Sara,Smith
Johnson,John
Running Command directly in shell:
PS C:\Users\x103673.MYL> import-csv C:\Users\x103673.MYL\Desktop\names.csv | forEach { Get-Aduser -filter {surname -eq $_.Last -and givenname -eq $_.First } -properties SAMAccountName | Select SamAccountName | Export-CSV C:\users\x103673.myl\desktop\usersout.csv}
Receiving error:
Get-ADUser : Property: 'Last' not found in object of type: 'System.Management.Automation.PSCustomObject'.