mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
49 lines
1.1 KiB
PowerShell
49 lines
1.1 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Removes a config entry from a given path
|
|
.DESCRIPTION
|
|
Removes a config entry from a given path
|
|
.FUNCTIONALITY
|
|
Removes a config entry from a given path
|
|
.EXAMPLE
|
|
PS>Remove-IcingaPowerShellConfig -Path 'framework.daemons';
|
|
.PARAMETER Path
|
|
The path to the config item to remove
|
|
.INPUTS
|
|
System.Object
|
|
.LINK
|
|
https://github.com/Icinga/icinga-powershell-framework
|
|
#>
|
|
|
|
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;
|
|
}
|