Adds support to fully uninstall the Icinga 2 agent including ProgramData

Fixes #67
This commit is contained in:
Lord Hepipud 2020-05-22 12:19:03 +02:00
parent 84975a4759
commit d983f6f767

View file

@ -1,5 +1,9 @@
function Uninstall-IcingaAgent()
{
param (
[switch]$RemoveDataFolder = $FALSE
);
$IcingaData = Get-IcingaAgentInstallation;
if ($IcingaData.Installed -eq $FALSE) {
@ -18,6 +22,14 @@ function Uninstall-IcingaAgent()
return $FALSE;
}
if ($RemoveDataFolder) {
[string]$IcingaProgramData = Join-Path -Path $Env:ProgramData -ChildPath 'icinga2';
Write-IcingaConsoleNotice -Message 'Removing Icinga 2 directoy from ProgramData: "{0}"' -Objects $IcingaProgramData;
if ((Remove-ItemSecure -Path $IcingaProgramData -Recurse -Force) -eq $FALSE) {
return $FALSE;
}
}
Write-IcingaConsoleNotice 'Icinga Agent was successfully removed';
return $TRUE;
}