From 2427c61d46131a6657bd4eff361129e3e8ca7d56 Mon Sep 17 00:00:00 2001 From: pm091 Date: Mon, 20 May 2019 16:53:39 +0100 Subject: [PATCH] Retrieve 1st line only from input file Retrieves the 1st line only to avoid passing the file object across the pipeline. --- Validate-CSVHeaders.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Validate-CSVHeaders.ps1 b/Validate-CSVHeaders.ps1 index 35b4b09..ae3ae84 100644 --- a/Validate-CSVHeaders.ps1 +++ b/Validate-CSVHeaders.ps1 @@ -8,7 +8,7 @@ function Validate-CSVHeaders ($correctHeaders) { [ValidateSet('Yes','No')]$validateHeaders = Read-Host "Validate headers?" if ($validateHeaders -eq 'Yes') { # put all the headers into a comma separated array - $headers = (Get-Content $fileName | Select-Object -First 1).Split(",") + $headers = (Get-Content $fileName -TotalCount 1).Split(",") for ($i = 0; $i -lt $headers.Count; $i++) { # trim any leading white space and compare the headers @@ -21,4 +21,4 @@ function Validate-CSVHeaders ($correctHeaders) { } } -Validate-CSVHeaders $correctHeaders \ No newline at end of file +Validate-CSVHeaders $correctHeaders