Archive for September, 2014

How to skip the first line with import-csv

Wednesday, September 3rd, 2014

I had a “quick and dirty” script to examine a list of hosts from a CSV.

There was a header with the data and I didn’t want the error that would pop up at the end of the foreach loop.

To get around the first line; I used a pipe and the select statement:

Import-Csv $file -header(“Hostname”, “OldIP”, “NewIP”) | select -Skip 1 | foreach {

Simple and it avoids a comparison check in the code.

The only thing to be concerned is if there are times there will be files without a header.