Created
September 16, 2025 16:36
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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