Skip to content

Instantly share code, notes, and snippets.

@Satak
Last active January 3, 2023 18:30
Show Gist options
  • Save Satak/a6436df92d3785135a63c05d6a99f18d to your computer and use it in GitHub Desktop.
Save Satak/a6436df92d3785135a63c05d6a99f18d to your computer and use it in GitHub Desktop.
$files = Get-ChildItem -Recurse -Filter '*.json' -Path 'Users'
$delimit = '---'
foreach ($file in $files) {
$yamlFileName = Join-Path $file.DirectoryName "$($file.BaseName).yaml"
$content = Get-Content $file -Raw
if ($content -match $delimit) {
$yamlDocs = $content.split($delimit) | ForEach-Object { $_ | ConvertFrom-Json -Depth 5 | ConvertTo-Yaml }
$yamlStr = $yamlDocs -join "$delimit`n"
}
else {
$yamlStr = $content | ConvertFrom-Json -Depth 5 | ConvertTo-Yaml
}
$yamlStr | Out-File $yamlFileName -Force -Encoding utf8 -NoNewline
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment