Skip to content

Instantly share code, notes, and snippets.

@rezamt
Created September 8, 2024 10:13
Show Gist options
  • Save rezamt/87c6ba2e5bcdf0027b36302f33c8e058 to your computer and use it in GitHub Desktop.
Save rezamt/87c6ba2e5bcdf0027b36302f33c8e058 to your computer and use it in GitHub Desktop.
poweshell

Read YAML and generate Markdown

param( [Parameter(Mandatory=$true)] [string]$YamlFilePath,

[Parameter(Mandatory=$true)]
[string]$OutputMarkdownPath

)

Import the PowerShell-Yaml module

Make sure to install it first: Install-Module -Name powershell-yaml

Import-Module powershell-yaml

Read the YAML file

$yamlContent = Get-Content -Path $YamlFilePath -Raw $yamlData = ConvertFrom-Yaml $yamlContent

Initialize the Markdown content

$markdownContent = ""

Group the data by applicationName

$groupedData = $yamlData | Group-Object -Property applicationName

foreach ($group in $groupedData) { $applicationName = $group.Name $markdownContent += "# $applicationNamen" $markdownContent += "| permissionid | permission name |n" $markdownContent += "|--------------|-----------------|`n"

foreach ($item in $group.Group) {
    foreach ($permission in $item.permissions) {
        $markdownContent += "| $($permission.id) | $($permission.name) |`n"
    }
}

$markdownContent += "`n"

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment