-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathUninstall-IcingaAgent.psm1
41 lines (34 loc) · 1.58 KB
/
Uninstall-IcingaAgent.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function Uninstall-IcingaAgent()
{
param (
[switch]$RemoveDataFolder = $FALSE
);
$IcingaData = Get-IcingaAgentInstallation;
[string]$IcingaProgramData = Join-Path -Path $Env:ProgramData -ChildPath 'icinga2';
if ($IcingaData.Installed -eq $FALSE) {
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;
}
Stop-IcingaService -Service 'icinga2';
$Uninstaller = Invoke-IcingaWindowsScheduledTask -JobType UninstallAgent -FilePath $IcingaData.Uninstaller;
if ($Uninstaller.ExitCode -ne 0) {
Write-IcingaConsoleError ([string]::Format('Failed to remove Icinga Agent: {0}{1}', $Uninstaller.Message, $Uninstaller.Error));
return $FALSE;
}
if ($RemoveDataFolder) {
Write-IcingaConsoleNotice -Message 'Removing Icinga Agent directory: "{0}"' -Objects $IcingaProgramData;
if ((Remove-ItemSecure -Path $IcingaProgramData -Recurse -Force) -eq $FALSE) {
return $FALSE;
}
}
Write-IcingaConsoleNotice 'Icinga Agent was successfully removed';
return $TRUE;
}