Я не совсем уверен, что вы спрашиваете здесь, но мне кажется, что вы хотите получить заголовки файла CSV в виде массива: ( Возьмите первую строку (сзаголовки) и добавьте его в массив в powershell )
Если это так, вот небольшая функция, которая может сделать это для вас:
function Get-CsvHeaders {
# returns an array with the names of the headers in a csv file in the correct order
[CmdletBinding(DefaultParameterSetName = 'ByDelimiter')]
param(
[Parameter(ValueFromPipeline = $true, Mandatory = $true, Position = 0)]
[ValidateScript({Test-Path -Path $_ -PathType Leaf})]
[string]$Path,
[Parameter(Mandatory = $false)]
[ValidateSet ('ASCII', 'BigEndianUnicode', 'Default', 'OEM', 'Unicode', 'UTF32', 'UTF7', 'UTF8')]
[string]$Encoding = $null,
[Parameter(Mandatory = $false, ParameterSetName = 'ByDelimiter')]
[char]$Delimiter = ',',
[Parameter(Mandatory = $false, ParameterSetName = 'ByCulture')]
[switch]$UseCulture
)
$splatParams = @{ 'Path' = $Path }
switch ($PSCmdlet.ParameterSetName) {
'ByDelimiter' { $splatParams.Delimiter = $Delimiter; break }
'ByCulture' { $splatParams.UseCulture = $true; break }
}
if ($Encoding) { $splatParams.Encoding = $Encoding }
$data = Import-Csv @splatParams -ErrorAction SilentlyContinue
$data[0].PSObject.properties.name
}
Использование:
$headersArray = Get-CsvHeaders -Path 'test.csv'