powershell filter csv

csv, powershell

Solution

For the first part, you can use `Select-String -Notmatch ...` e.g.:

$file = "data.csv"
$csv = Get-Content $file
$csv | Select-String -Notmatch 'Not Installed' | Out-File $file -Enc ascii

If your CSV file happens to be Unicode, then remove the "-Enc ascii" part since the default for Out-File is Unicode. As for the second part of your question, you're going to need to be bit more specific. However, you should look at the help on Import-Csv and Export-Csv:

man Import-Csv -full
man Export-Csv -full

Problem

Looking for help on best practice as I am Powershell newbie, I have a csv file and I would like to filter out every row in the csv except for the rows containing "Not Installed" I would then like to filter those results against a separate csv files housing a list of computers and also exclude any rows containing a match. Any help or starting points would be appreciated !

Original source