Skip to content

Instantly share code, notes, and snippets.

@sean-mcardle
Created September 16, 2025 16:36
Show Gist options
  • Select an option

  • Save sean-mcardle/c1853e7607ed9eb1c0c99543ca757f35 to your computer and use it in GitHub Desktop.

Select an option

Save sean-mcardle/c1853e7607ed9eb1c0c99543ca757f35 to your computer and use it in GitHub Desktop.
Script for converting a CSV file to markdown. Note: the CSV is loaded into memory, not streamed from disk. Probably not suitable for large files.
function CsvToMd {
param ($PathToCsv)
if (-not (Test-Path $PathToCsv)) {
throw [System.IO.FileNotFoundException]::new("Provided path doesn't resolve to a CSV file", $PathToCsv)
}
$records = import-csv $PathToCsv
$header = ($records | select -First 1).PSObject.Properties.Name
$headerLine = $header -join ' | '
$headerDivider = (1.. ($header.Count) | foreach { '---' } ) -join '|'
Write-Output $headerLine
Write-Output $headerDivider
Write-Output $records | ConvertTo-Csv -NoTypeInformation -Delimiter '|' | foreach { $_.Replace('"','') } | select -Skip 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment