2019-09-29 12:25:40 -04:00
|
|
|
function Uninstall-IcingaAgent()
|
|
|
|
|
{
|
|
|
|
|
$IcingaData = Get-IcingaAgentInstallation;
|
|
|
|
|
|
|
|
|
|
if ($IcingaData.Installed -eq $FALSE) {
|
2020-05-13 10:53:15 -04:00
|
|
|
Write-IcingaConsoleError 'Unable to uninstall the Icinga Agent. The Agent is not installed';
|
2019-09-29 12:25:40 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 10:53:15 -04:00
|
|
|
Write-IcingaConsoleNotice 'Removing current installed Icinga Agent';
|
2019-09-29 12:25:40 -04:00
|
|
|
|
2019-10-31 09:31:49 -04:00
|
|
|
Stop-IcingaService 'icinga2';
|
|
|
|
|
|
2019-09-29 12:25:40 -04:00
|
|
|
$Uninstaller = Start-IcingaProcess -Executable 'MsiExec.exe' -Arguments ([string]::Format('{0} /q', $IcingaData.Uninstaller)) -FlushNewLine;
|
|
|
|
|
|
|
|
|
|
if ($Uninstaller.ExitCode -ne 0) {
|
2020-05-13 10:53:15 -04:00
|
|
|
Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga 2 Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error));
|
2019-09-29 12:25:40 -04:00
|
|
|
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;
|
|
|
|
|
}
|