2019-09-29 12:25:40 -04:00
|
|
|
function Uninstall-IcingaAgent()
|
|
|
|
|
{
|
2020-05-22 06:19:03 -04:00
|
|
|
param (
|
|
|
|
|
[switch]$RemoveDataFolder = $FALSE
|
|
|
|
|
);
|
|
|
|
|
|
2020-05-30 08:42:31 -04:00
|
|
|
$IcingaData = Get-IcingaAgentInstallation;
|
|
|
|
|
[string]$IcingaProgramData = Join-Path -Path $Env:ProgramData -ChildPath 'icinga2';
|
2019-09-29 12:25:40 -04:00
|
|
|
|
|
|
|
|
if ($IcingaData.Installed -eq $FALSE) {
|
2020-05-30 08:42:31 -04:00
|
|
|
Write-IcingaConsoleNotice 'Unable to uninstall the Icinga Agent. The Agent is not installed';
|
|
|
|
|
if ($RemoveDataFolder) {
|
|
|
|
|
if (Test-Path $IcingaProgramData) {
|
|
|
|
|
Write-IcingaConsoleNotice -Message 'Removing Icinga Agent directory: "{0}"' -Objects $IcingaProgramData;
|
|
|
|
|
return ((Remove-ItemSecure -Path $IcingaProgramData -Recurse -Force) -eq $FALSE);
|
|
|
|
|
} else {
|
|
|
|
|
Write-IcingaConsoleNotice -Message 'Icinga Agent directory "{0}" does not exist' -Objects $IcingaProgramData;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $FALSE;
|
2019-09-29 12:25:40 -04:00
|
|
|
}
|
|
|
|
|
|
2022-02-15 09:14:27 -05:00
|
|
|
Stop-IcingaService -Service 'icinga2';
|
2020-05-30 08:42:31 -04:00
|
|
|
|
2022-04-27 06:43:55 -04:00
|
|
|
$Uninstaller = & powershell.exe -Command {
|
|
|
|
|
$IcingaData = $args[0];
|
2020-05-30 08:42:31 -04:00
|
|
|
$Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q', $IcingaData.Uninstaller)) -FlushNewLine;
|
2019-10-31 09:31:49 -04:00
|
|
|
|
2022-02-15 09:14:27 -05:00
|
|
|
Start-Sleep -Seconds 2;
|
|
|
|
|
Optimize-IcingaForWindowsMemory;
|
|
|
|
|
|
2020-05-30 08:42:31 -04:00
|
|
|
return $Uninstaller;
|
2022-04-27 06:43:55 -04:00
|
|
|
} -Args $IcingaData;
|
2019-09-29 12:25:40 -04:00
|
|
|
|
|
|
|
|
if ($Uninstaller.ExitCode -ne 0) {
|
2020-05-22 07:42:23 -04:00
|
|
|
Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error));
|
2019-09-29 12:25:40 -04:00
|
|
|
return $FALSE;
|
|
|
|
|
}
|
2020-05-22 06:19:03 -04:00
|
|
|
|
|
|
|
|
if ($RemoveDataFolder) {
|
2020-05-22 07:42:23 -04:00
|
|
|
Write-IcingaConsoleNotice -Message 'Removing Icinga Agent directory: "{0}"' -Objects $IcingaProgramData;
|
2020-05-22 06:19:03 -04:00
|
|
|
if ((Remove-ItemSecure -Path $IcingaProgramData -Recurse -Force) -eq $FALSE) {
|
|
|
|
|
return $FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 10:53:15 -04:00
|
|
|
Write-IcingaConsoleNotice 'Icinga Agent was successfully removed';
|
2019-09-29 12:25:40 -04:00
|
|
|
return $TRUE;
|
|
|
|
|
}
|