mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
32 lines
840 B
PowerShell
32 lines
840 B
PowerShell
|
|
function Set-IcingaPowerShellConfig()
|
||
|
|
{
|
||
|
|
param(
|
||
|
|
$Path = '',
|
||
|
|
$Value = $null
|
||
|
|
);
|
||
|
|
|
||
|
|
$Config = Read-IcingaPowerShellConfig;
|
||
|
|
$PathArray = $Path.Split('.');
|
||
|
|
$ConfigObject = $Config;
|
||
|
|
[int]$Index = $PathArray.Count;
|
||
|
|
$InputValue = $null;
|
||
|
|
foreach ($entry in $PathArray) {
|
||
|
|
if ($index -eq 1) {
|
||
|
|
$InputValue = $Value;
|
||
|
|
}
|
||
|
|
if (-Not (Test-IcingaPowerShellConfigItem -ConfigObject $ConfigObject -ConfigKey $entry)) {
|
||
|
|
New-IcingaPowerShellConfigItem -ConfigObject $ConfigObject -ConfigKey $entry -ConfigValue $InputValue;
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($index -eq 1) {
|
||
|
|
$ConfigObject.$entry = $Value;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
$ConfigObject = $ConfigObject.$entry;
|
||
|
|
$index -= 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
Write-IcingaPowerShellConfig $Config;
|
||
|
|
}
|