Icinga2 Powershell Framework - Installation help

Hi,

I´ve used icinga2 windows agent with nscp+ plugin. Although it is developed, it doesn´t work on some computers, so I would like to migrate to Icinga2 Power Shell Framework.

I´m using icinga2 director and would like to add a new host. Icinga2 windows agent is running on this machine, and now I would like to install / use the powershell framework.

I´ve opened an elevated powershell with the following commands:

Set-ExecutionPolicy -ExecutionPolicy ByPass -Scope Process

And after adding the host at icinga the following powershell:

 [Net.ServicePointManager]::SecurityProtocol = 'tls12, tls11';
>> $ProgressPreference                         = 'SilentlyContinue';
>> [string]$ScriptFile                         = 'C:\Users\Public\IcingaForWindows.ps1';
>>
>> Invoke-WebRequest `
>>     -UseBasicParsing `
>>     -Uri             'https://packages.icinga.com/IcingaForWindows/IcingaForWindows.ps1' `
>>     -OutFile         $ScriptFile;
>>
>> & $ScriptFile `
>>     -ModuleDirectory  'C:\Program Files\WindowsPowerShell\Modules\' `
>>     -InstallCommand   '{"IfW-DirectorSelfServiceKey":{"Values":["313483a65a43de86f616"]},"IfW-DirectorUrl":{"Values":["http://te-icinga-vm.xy.at/director/"]},"IfW-StableRepository":{"Values":["https://packages.icinga.com/IcingaForWindows/stable"]}}' `
>>     -IcingaRepository 'https://packages.icinga.com/IcingaForWindows/stable/ifw.repo.json'

The code works, but the installation stucks at:

[Notice]: PowerShell Execution-Policies are configured to run Scripts and/or Modules.
[Notice]: Icinga PowerShell Framework is already installed. Using Framework functions for kickstarter.
[Notice]: Loading Icinga PowerShell Framework.

Nothing happens anymore. Have understood it wrong how to use the powershell module? Any hints welcome :slight_smile:

Hi @meisterpropper,
I can’t be certain in which state the system is, but what happens if you open a new Powershell and enter icinga into it?

If that works, the module itself should be installed and Ok. that would be a first step forward.

Thanks,
I got an error:

icinga : Der Befehl "icinga" wurde im Modul "icinga-powershell-framework" gefunden, das Modul konnte aber nicht
geladen werden. Wenn Sie weitere Informationen wünschen, führen Sie "Import-Module icinga-powershell-framework" aus.
In Zeile:1 Zeichen:1
+ icinga
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (icinga:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

I guess Import-Module icinga-powershell-framework does not work either?

Well it works, when I set
Set-ExecutionPolicy -ExecutionPolicy ByPass -Scope Process
before.

Can it be that during the installation the system / user needs to be set to ByPass at Execution Policy? Is there any chance to get a signed / valid execution policy?

Hm, I am not the expert for that (@cstein might know more),
but I think that the problem is, that Microsoft wants developers to throw money
at them to comply with their security circus and the added workload
is too much for a small amount of comfort.
But I might be wrong here.

If I remove all files from C:\Programm Files\Windows Powershell\icinga-powershellframework and install it from scratch - I get the following output. It get stuck at a different position (last line).

[Notice]: PowerShell Execution-Policies are configured to run Scripts and/or Modules.
[Notice]: Downloading Icinga PowerShell Framework into "C:\Users\wadmin\AppData\Local\Temp\icinga-powershell-framework-zip"
[Notice]: Installing Icinga PowerShell Framework into "C:\Program Files\WindowsPowerShell\Modules\"
[Notice]: Installing new Icinga PowerShell Framework version
[Notice]: Unblocking Icinga PowerShell Framework files
[Notice]: Applying pending migrations required for Icinga for Windows v1.8.0
[Notice]: Applying pending migrations required for Icinga for Windows v1.10.0
[Notice]: Applying pending migrations required for Icinga for Windows v1.10.1
[Notice]: Applying pending migrations required for Icinga for Windows v1.12.0
[Notice]: The task "Renew Certificate" has been successfully registered at location "\Icinga\Icinga for Windows\".
[Notice]: Applying pending migrations required for Icinga for Windows v1.12.1
[Notice]: The task "Renew Certificate" has been successfully registered at location "\Icinga\Icinga for Windows\".
[Notice]: Applying pending migrations required for Icinga for Windows v1.12.2
[Notice]: The task "Renew Certificate" has been successfully registered at location "\Icinga\Icinga for Windows\".
[Warning]: The service "icingapowershell" is not installed
[Warning]: The service "icingapowershell" is not installed
[Notice]: Applying pending migrations required for Icinga for Windows v1.12.3
[Notice]: The task "Renew Certificate" has been successfully registered at location "\Icinga\Icinga for Windows\".
[Warning]: The service "icingapowershell" is not installed
[Warning]: The service "icingapowershell" is not installed
[Notice]: Applying pending migrations required for Icinga for Windows v1.13.0
[Notice]: Windows Eventlog configuration has been written successfully to use severity level: warning - Please restart the Icinga Agent to apply this change
[Notice]: The task "Set Process Priority" has been successfully registered at location "\Icinga\Icinga for Windows\".
[Notice]: Applying pending migrations required for Icinga for Windows v1.13.0.1
[Notice]: The task "Set Process Priority" has been successfully registered at location "\Icinga\Icinga for Windows\".

And it stays there forever?

Yes, I could install it now after deleting all files and installing it again using two different Execution policy scopes: LocalMachine and CurrentUser. It seems that LocalMachine did the trick.

But I am not 100% sure, if the installation works. Really new to this kind of configuration.

It looks like your installation is getting stuck after loading the Icinga PowerShell Framework. This could be due to leftover configurations or execution policy restrictions. Here’s how you can resolve it:


Ensure Execution Policy is Set Correctly

Before proceeding, ensure the execution policy is correctly set to Unrestricted

$currentPolicy = Get-ExecutionPolicy -Scope LocalMachine
If ($currentPolicy -ne 'Unrestricted') {
    Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force
    Write-Host "Execution policy changed to Unrestricted."
} Else {
    Write-Host "Execution policy already set to Unrestricted."
}

Restart PowerShell after applying this change.


** Cleanup Existing Icinga PowerShell Modules**

Before reinstalling, remove any existing Icinga modules to prevent conflicts:

Function Cleanup-PowerShellModules {
    $modulePath = "C:\Program Files\WindowsPowerShell\Modules"
    $icingaModules = Get-ChildItem -Path $modulePath | Where-Object { $_.Name -like "Icinga-*" }
    
    if ($icingaModules.Count -gt 0) {
        foreach ($module in $icingaModules) {
            if (Get-Module -Name $module.Name -ListAvailable) {
                Remove-Module -Name $module.Name -Force
                Write-Host "Module $($module.Name) unloaded."
            }
            Remove-Item -Path $module.FullName -Recurse -Force
            Write-Host "Module $($module.Name) removed."
        }
    }
}
Cleanup-PowerShellModules

Run this function to remove all existing Icinga PowerShell modules.