mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
31 lines
840 B
PowerShell
31 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;
|
|
}
|