Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Unable to search by CSV Column name

$
0
0

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,First
Smith,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'.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>