Search multiple variables with Where-Object

26 Views Asked by At

I'm really hoping somebody can put me out of hours of searching for an answer on this one.

I'm running a script against a CSV to locate a set value (servers) in column B and delete the row if they are found. The script works when I pass a single parameter through it, but when I try with multiple strings or a variable it doesn't work.

$H = 1..40
$Data = Get-Content "Pre-Test.csv" | Select-Object -Skip 1 | ConvertFrom-Csv -Header $h
$Data | Where-Object {$_.B -ne 'Server1' -or 'Server2' -or 'Server3'} | Export-Csv "Post-Test.csv"

I've also tried the following to no avail:

$H = 1..40
$Data = Get-Content "Pre-Test.csv" | Select-Object -Skip 1 | ConvertFrom-Csv -Header $h
$Data | Where-Object {$_.B -cin 'Server1', 'Server2', 'Server3'} | Export-Csv "Post-Test.csv"

and:

$H = 1..40
$Data = Get-Content "Pre-Test.csv" | Select-Object -Skip 1 | ConvertFrom-Csv -Header $h
$Data | Where-Object {$_.B -ne 'Server1', $_.B -ne 'Server2', $_.B -ne 'Server3'} | Export-Csv "Post-Test.csv"
0

There are 0 best solutions below