Skip to content
Snippets Groups Projects

Read JSON KV pairs to Consul with PowerShell

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Benedikt Heinrichs
    Edited
    snippetfile1.txt 594 B
    $fullPath = "{pathToConsulExecutable}"
    $configFile = "{configFileDirectory}"
    
    # helper to turn PSCustomObject into a list of key/value pairs
    function Get-ObjectMembers {
        [CmdletBinding()]
        Param(
            [Parameter(Mandatory=$True, ValueFromPipeline=$True)]
            [PSCustomObject]$obj
        )
        $obj | Get-Member -MemberType NoteProperty | ForEach-Object {
            $key = $_.Name
            [PSCustomObject]@{Key = $key; Value = $obj."$key"}
        }
    }
    
    $(Get-Content -Path $configFile -Raw) | ConvertFrom-Json | Get-ObjectMembers | ForEach-Object {
        & $fullPath kv put $_.Key $_.Value
    }
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment