Created
November 8, 2023 23:25
-
-
Save josy1024/c51bdd20c142f5b3ffb3634c577c1603 to your computer and use it in GitHub Desktop.
simple get-configuration from json array (file)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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