I need to drop from multiple rows from a CSV. I've seen this code:
Get-Content "file.csv" | Where {$_.Column -ne "Known Value" |Export new.csv
But I can't figure out how to get it to work for my purposes. I have imported the CSV as a system object array. I am comparing all cells in the CSV to a hashtable as @{"column": "values"}. Anyone can go in and change these depending on what they need to remove from the CSV.
Here is the hashtable:
#data_entry.ps1 #file name
$remove_value_row = @{
"First_Name" = @("Benjamin","Ben");
"Last_Name" = @("Armour");
}
Here is my code:
#drop_rows.ps1
. .\data_entry.ps1
$csv = import-csv "\droprows.csv"
$csv |Where-Object {
for($i=0;$i -lt $csv.length;$i++){
foreach($key in $remove_value_row.Keys){
-not($remove_value_row[$key] -contains $csv[$i].($key))
#drop where a csv column 1. matches a key ,
#2. the cell value is one of the key-values.
}
}
} | Export "out.csv"
Get-Content.ifand a few brackets. I formatted the code so you can see it but your edit overwrote mine.