functionGet-CsvDelimiter($Path) { # get the header line $headerLine = Get-Content$Path | Select-Object-First1
# examine header line per character $headerline.ToCharArray() | # find all non-alphanumeric characters Where-Object { $_-notlike'[a-z0-9äöüß"()]' } | # find the one that occurs most often Group-Object-NoElement | Sort-Object-Descending-Property Count | # return it Select-Object-First1-ExpandProperty Name }
functionImport-CsvWithDuplicate($Path, $Delimiter=',', $Encoding='UTF8') { # get the header line and all header items $headerLine = Get-Content$Path | Select-Object-First1 $headers = $headerLine.Split($Delimiter)
# check for duplicate header names, and if found, add an incremented # number to it $dupDict = @{} $newHeaders = @(foreach($headerin$headers) { $incrementor = 1 $header = $header.Trim('"') $newheader = $header
# increment numbers until the new name is unique while ($dupDict.ContainsKey($newheader) -eq$true) { $newheader = "$header$incrementor" $incrementor++ }
$dupDict.Add($newheader, $header)
# return the new header, producing a string array $newheader })
# read the CSV without its own headers.. Get-Content-Path$Path-Encoding$Encoding | Select-Object-Skip1 | # ..and replace headers with newly created list ConvertFrom-CSV-Delimiter$Delimiter-Header$newHeaders }
#requires -Version 2.0 -Modules PKI # importing to personal store $Path = 'C:\Path\To\CertFile.cer' Import-Certificate-FilePath$Path-CertStoreLocation Cert:\CurrentUser\My