PowerShell File Format Conversion

Posted by John Liu on Wednesday, July 17, 2024

PowerShell has function to convert files between different formats.

To convert Json to CSV:

$procs = Get-Content -Path c:\temp\test.json | ConvertFrom-Json
$procs | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | Out-File c:\temp\test.csv

If the Json is nested

$procs = Get-Content -Path c:\temp\test.json | ConvertFrom-Json
$procs.Table1 | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | Out-File c:\temp\Table1.csv
$procs.Table2 | ConvertTo-Csv -Delimiter "`t" -NoTypeInformation | Out-File c:\temp\Table2.csv