The following script produces no output at all, not even an error:
Import-Csv input.csv | foreach {Get-ADUser -LDAPFilter "(&(givenName=$_.givenName)(sn=$_.sn))"}
The components work individually:
- Import-Csv input.csv
- Get-ADUser -LDAPFilter "(&(givenName=karl)(sn=foley))"
- Import-Csv input.csv | foreach {write-host $_.givenName,$_.sn}
I've also verified that there are no extra characters in the csv using:
Import-Csv input.csv | foreach {write-host $_.givenName,$_.givenName.length,$_.sn,$_.sn.length}
What am I doing wrong please?
Excellent (fast) answer from Mike Laughlin over on the Technet forums. It should be:
ReplyDeleteImport-Csv input.csv | foreach {Get-ADUser -LDAPFilter "(&(givenName=$($_.givenName))(sn=$($_.sn)))"}
Thanks!
http://social.technet.microsoft.com/Forums/en-US/8b96f7dc-632f-44d4-b789-419c1918b179/unable-to-match-users-from-a-csv-with-active-directory