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.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: