I am trying to filter out lines out of a csv that contain any of the values in an array.
Using this post as reference: Use -notlike to filter out multiple strings in PowerShell
I managed to get it working with this format:
Import-Csv "$LocalPath\Stripped1Acct$abbrMonth$Year.csv" |
where {$_."SubmitterName" -notlike "*${Report2a}*"
-and $_."SubmitterName" -notlike "*${Report2b}*"
-and $_."SubmitterName" -notlike "*${Report2c}*"} |
Export-Csv "$LocalPath\Stripped2Acct$abbrMonth$Year.csv" -NoTypeInformation
Eventually I plan to rewrite the script so it will pull the exclusion list from a text file generated by an end user. In order to do that, I'll have to have it access values in an array. I tried doing that with the following syntax, but it didn't work as intended:
Import-Csv "$LocalPath\Stripped1Acct$abbrMonth$Year.csv" |
where {$_."SubmitterName" -notlike "*${Report2[0]}*"
-and $_."SubmitterName" -notlike "*${Report2[1]}*"
-and $_."SubmitterName" -notlike "*${Report2[2]}*"} |
Export-Csv "$LocalPath\Stripped2Acct$abbrMonth$Year.csv" -NoTypeInformation
I have a feeling it's just an syntax issue, but after playing around with it for far too long, I've run out of ideas. I have a feeling it's a syntax issue