HardeningKitty icon indicating copy to clipboard operation
HardeningKitty copied to clipboard

possibility to get csv delimiter format with coma or semi-colon

Open racingtri opened this issue 11 months ago • 0 comments

Hello,

On some systems we have default value for regionnal settings based on ";" instead of ",". if the findingfile is open in excel and registered, by default (in france), Excel will transform it in semicolon delimiter.

A workaround could be to add a parameter allowing to personnalize the delimiter option in << Import-Csv -Path $FileFindingList -Delimiter "," >>

It could be possible to add it in the script : an other way could be t check on the firstline the presence of the delimiter and use it afterward ?

Read the first line of the file

$firstLine = Get-Content -Path $csvFilePath -TotalCount 1

Check for common delimiters

if ($firstLine -match ",") { Write-Output "The delimiter is a comma (,)." $Delimiter = "," } elseif ($firstLine -match ";") { Write-Output "The delimiter is a semicolon (;)." $Delimiter = ";" } elseif ($firstLine -match "t") { Write-Output "The delimiter is a tab (t)." $Delimiter = "`t" } else { Write-Output "The delimiter could not be determined. Please inspect the file manually." }

racingtri avatar May 15 '25 14:05 racingtri