Powershell e il problema dei CSV senza riga di intestazione
CSV files are great for passing information around and are very easy to use in your PowerShell scripts. Sometimes, your CSV may have a problem – for instance it doesn’t have a header row. At that point the data becomes a bit difficult to use:
£ Import-Csv .\htest.csv | Format-Table -AutoSize
Luckily there is an answer. Create your own headers:
£ Import-Csv .\htest.csv -Header “Number”, “Colour”, “Price”, “Total” | Format-Table -AutoSize
Makes much more sense now.
You can also override existing headers
£ Import-Csv .\htest.csv -Header “Number”, “Colour”, “Price”, “Total” |
>> select -Skip 1 | Format-Table -AutoSize
The select call is used to skip the old header row.
If you run queries in SQL Studio Management Studio and export the results to a CSV file you will get a file without headers. This technique comes in useful at that point.