Read JSON KV pairs to Consul with PowerShell
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
}
Please register or sign in to comment