2021-08-06 12:12:27 -04:00
|
|
|
function Uninstall-IcingaServiceUser()
|
|
|
|
|
{
|
|
|
|
|
param (
|
|
|
|
|
$IcingaUser = 'icinga'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ([string]::IsNullOrEmpty($IcingaUser)) {
|
|
|
|
|
Write-IcingaConsoleError 'The provided user cannot be empty.';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-IcingaConsoleNotice 'Uninstalling user "{0}"' -Objects $IcingaUser;
|
|
|
|
|
|
2025-12-23 11:25:23 -05:00
|
|
|
# Fetch the current service user and SID
|
|
|
|
|
$ServiceUser = Get-IcingaServiceUser;
|
|
|
|
|
$ServiceUserSID = Get-IcingaUserSID $ServiceUser;
|
|
|
|
|
|
2021-08-06 12:12:27 -04:00
|
|
|
Stop-IcingaService 'icinga2';
|
2024-09-19 06:27:06 -04:00
|
|
|
Stop-IcingaForWindows;
|
2021-08-06 12:12:27 -04:00
|
|
|
|
|
|
|
|
Set-IcingaPowerShellConfig -Path 'Framework.Icinga.ServiceUser' -Value '';
|
|
|
|
|
|
|
|
|
|
Set-IcingaServiceUser -User 'NT Authority\NetworkService' -Service 'icinga2' | Out-Null;
|
|
|
|
|
Set-IcingaServiceUser -User 'NT Authority\NetworkService' -Service 'icingapowershell' | Out-Null;
|
|
|
|
|
|
|
|
|
|
Set-IcingaUserPermissions -IcingaUser $IcingaUser -Remove;
|
2025-12-23 11:25:23 -05:00
|
|
|
Update-IcingaWindowsUserPermission -SID $ServiceUserSID -Remove;
|
2021-08-06 12:12:27 -04:00
|
|
|
|
2025-12-23 11:25:23 -05:00
|
|
|
Remove-IcingaWindowsUser -IcingaUser $IcingaUser | Out-Null;
|
2021-08-06 12:12:27 -04:00
|
|
|
|
|
|
|
|
Restart-IcingaService 'icinga2';
|
2024-03-13 11:50:36 -04:00
|
|
|
Restart-IcingaForWindows;
|
2021-08-06 12:12:27 -04:00
|
|
|
|
|
|
|
|
Write-IcingaConsoleNotice 'User "{0}" including permissions was removed from this host' -Objects $IcingaUser;
|
|
|
|
|
}
|