I have been working on importing a CSV in Powershell to then export only specific columns 2,3 and 5 and ignoring the last line.
TestFile.csv
:
"1","2","3","4","5" "1","2","3","4","5" "1","2","3","4","5" "1","2","3","4","5" "1","2","3","4","5" ,,,2,2,2,,,2,,
PowerShell script used:
Import-Csv '\\DESKTOP-QC1GB24\Allpay DD\Processing\TestFile.csv' -Header (1..5|%{"Column$_"}) |
Select-Object Column2, Column3, Column5 -SkipLast 1 |
Export-Csv -Path "\\DESKTOP-QC1GB24\Allpay DD\Completed\New.CSV"
Results I am getting (new.csv
):
#TYPE Selected.System.Management.Automation.PSCustomObject "Column2","Column3","Column5" "2","3","5" "2","3","5" "2","3","5" "2","3","5" "2","3","5"
The problem I face is its exporting the temp column headers and some text above my data. Is there a way to exclude this? Also id like to keep the original name of the file is there a way to export with original filename + _new?