icinga-powershell-framework/lib/config/Remove-IcingaPowerShellConfig.psm1

33 lines
765 B
PowerShell
Raw Normal View History

function Remove-IcingaPowerShellConfig()
{
param(
$Path = ''
);
if ([string]::IsNullOrEmpty($Path)) {
throw 'Please specify a valid path to an object';
}
$Config = Read-IcingaPowerShellConfig;
$PathArray = $Path.Split('.');
$ConfigObject = $Config;
[int]$Index = $PathArray.Count;
foreach ($entry in $PathArray) {
if (-Not (Test-IcingaPowerShellConfigItem -ConfigObject $ConfigObject -ConfigKey $entry)) {
return $null;
}
if ($index -eq 1) {
$ConfigObject.PSObject.Properties.Remove($entry);
break;
}
$ConfigObject = $ConfigObject.$entry;
$Index -= 1;
}
Write-IcingaPowerShellConfig $Config;
}