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 }