|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | + Uninstalls every PowerShell module within the icinga-powershell-* namespace |
| 4 | + including the Icinga Agent with all components (like certificates) as well as |
| 5 | + the Icinga for Windows service and the Icinga PowerShell Framework. |
| 6 | +.DESCRIPTION |
| 7 | + Uninstalls every PowerShell module within the icinga-powershell-* namespace |
| 8 | + including the Icinga Agent with all components (like certificates) as well as |
| 9 | + the Icinga for Windows service and the Icinga PowerShell Framework. |
| 10 | +.FUNCTIONALITY |
| 11 | + Uninstalls every PowerShell module within the icinga-powershell-* namespace |
| 12 | + including the Icinga Agent with all components (like certificates) as well as |
| 13 | + the Icinga for Windows service and the Icinga PowerShell Framework. |
| 14 | +.PARAMETER Force |
| 15 | + Suppress the question if you are sure to uninstall everything |
| 16 | +.INPUTS |
| 17 | + System.String |
| 18 | +.OUTPUTS |
| 19 | + Null |
| 20 | +.LINK |
| 21 | + https://github.com/Icinga/icinga-powershell-framework |
| 22 | +#> |
| 23 | + |
| 24 | +function Uninstall-IcingaForWindows() |
| 25 | +{ |
| 26 | + param ( |
| 27 | + [switch]$Force = $FALSE |
| 28 | + ); |
| 29 | + |
| 30 | + $ModuleList = Get-Module 'icinga-powershell-*' -ListAvailable; |
| 31 | + [string]$Modules = [string]::Join(', ', $ModuleList.Name); |
| 32 | + |
| 33 | + if ($Force -eq $FALSE) { |
| 34 | + Write-IcingaConsoleWarning -Message 'You are about to uninstall the Icinga Agent with all components (including certificates) and all Icinga for Windows Components: {0}{1}Are you sure you want to proceed? (y/N)' -Objects $Modules, (New-IcingaNewLine); |
| 35 | + $Input = Read-Host 'Confirm uninstall'; |
| 36 | + if ($input -ne 'y') { |
| 37 | + return; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + $CurrentLocation = Get-Location; |
| 42 | + |
| 43 | + if ($CurrentLocation -eq (Join-Path -Path (Get-IcingaFrameworkRootPath) -ChildPath 'icinga-powershell-framework')) { |
| 44 | + Set-Location -Path (Get-IcingaFrameworkRootPath); |
| 45 | + } |
| 46 | + |
| 47 | + Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows from this host'; |
| 48 | + Write-IcingaConsoleNotice 'Uninstalling Icinga Agent'; |
| 49 | + Uninstall-IcingaAgent -RemoveDataFolder | Out-Null; |
| 50 | + Write-IcingaConsoleNotice 'Uninstalling Icinga for Windows service'; |
| 51 | + Uninstall-IcingaFrameworkService | Out-Null; |
| 52 | + |
| 53 | + $HasErrors = $FALSE; |
| 54 | + |
| 55 | + foreach ($module in $ModuleList.Name) { |
| 56 | + [string]$ModuleName = $module.Replace('icinga-powershell-', ''); |
| 57 | + |
| 58 | + if ((Uninstall-IcingaFrameworkComponent -Component $ModuleName)) { |
| 59 | + continue; |
| 60 | + } |
| 61 | + |
| 62 | + $HasErrors = $TRUE; |
| 63 | + } |
| 64 | + |
| 65 | + Remove-Module 'icinga-powershell-framework' -Force -ErrorAction SilentlyContinue; |
| 66 | + |
| 67 | + if ($HasErrors) { |
| 68 | + Write-IcingaConsoleWarning 'Not all components could be removed. Please ensure no other PowerShell/Application is currently open and accessing Icinga for Windows files'; |
| 69 | + } else { |
| 70 | + Write-IcingaConsoleNotice 'Icinga for Windows was removed from this host.'; |
| 71 | + } |
| 72 | +} |
0 commit comments