I'd like to use the following script to reduce a huge CSV file to a useful state, but it's eliminating the header row of the CSV. I understand from reading past questions/solutions here that I can use Select -Skip 1 or Select -Skip 1 to preserve the header, but I'm not sure how to integrate Select into my script gracefully. Do I need to start over with this or does someone have a simple solution?
$SourceFile = 'C:\Temp\Monthly_Report.CSV'
$Pattern = '.GBL|.aspx'
(Get-Content $SourceFile) | Where-Object {
$_ -match $Pattern
} | Set-Content $SourceFile
This is the content of "Monthly_Report.CSV" before I run the script:
