Skip to content

Instantly share code, notes, and snippets.

@josy1024
Created November 8, 2023 23:25
Show Gist options
  • Save josy1024/c51bdd20c142f5b3ffb3634c577c1603 to your computer and use it in GitHub Desktop.
Save josy1024/c51bdd20c142f5b3ffb3634c577c1603 to your computer and use it in GitHub Desktop.
simple get-configuration from json array (file)
function Get-ConfigurationfromJSON {
<#
.SYNOPSIS
json array config file
.DESCRIPTION
use a json config file
.EXAMPLE
# $config = Get-Configuration -match "2" -config .\mandant.json
# $config.ConfigValue
#>
param (
[string]$config="config.json",
[string]$id="id",
[string]$match
)
# Read the JSON file
$json = Get-Content -Path $config | ConvertFrom-Json
# Find the object with the matching "anbieternr"
$result = $json | Where-Object { $_.($id) -eq $match }
if ($result) {
return $result
} else {
Write-Host "No configuration found for $id : $match"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment