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 !
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
get-help *csv*
get-help import-csv -examples
example csv file called test.txt
header1,header2,header3
installed,2,3
not installed,2,3
Import the file into a powershell variable and filter it.
$p = Import-CSV .\test.txt
$p | Where { $_.header1 -eq 'installed'}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With