Skip to content

Commit d6ee0ed

Browse files
committed
Extends KB for execution policy and path
1 parent b24ebd8 commit d6ee0ed

File tree

3 files changed

+174
-1
lines changed

3 files changed

+174
-1
lines changed

Diff for: doc/10-Knowledge-Base.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ For this reason you will find a list of Icinga knowledge base entries below. Ent
1010
| --- | --- |
1111
| [IWKB000001](knowledgebase/IWKB000001.md) | The user you are running this command as does not have permission to access the requested Cim-Object. To fix this, please add the user the Agent is running with to the "Remote Management Users" groups and grant access to the WMI branch for the Class/Namespace mentioned above and add the permission "Remote enable". |
1212
| [IWKB000002](knowledgebase/IWKB000002.md) | Plugin execution fails because arguments could not be validated and properly set. An example error could be `The "*" was not recognized as the name of a program, cmdlet, function, script file, or executable. Check the spelling of the name and that the path is correct (if included), and repeat the process.` |
13-
| [IWKB000003](knowledgebase/IWKB000003.md) | The Icinga Agent service `icinga2` cannot be started/modified/added because it is marked for deletion. |
13+
| [IWKB000003](knowledgebase/IWKB000003.md) | The Icinga Agent service `icinga2` cannot be started/modified/added because it is marked for deletion. |
14+
| [IWKB000004](knowledgebase/IWKB000004.md) | Use-Icinga : The 'Use-Icinga' command was found in the module 'icinga-powershell-framework', but the module could not be loaded. For more information, run 'Import-Module icinga-powershell-framework' |
15+
| [IWKB000005](knowledgebase/IWKB000005.md) | powershell.exe : Failed to start service 'Icinga PowerShell Service (icingapowershell)'. |

Diff for: doc/knowledgebase/IWKB000004.md

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Icinga Knowledge Base - IWKB000004
2+
3+
## Short Message
4+
5+
Use-Icinga : The 'Use-Icinga' command was found in the module 'icinga-powershell-framework', but the module could not be loaded. For more information, run 'Import-Module icinga-powershell-framework'
6+
7+
## Example Exception
8+
9+
Use-Icinga : The 'Use-Icinga' command was found in the module 'icinga-powershell-framework', but the module could not be loaded. For more information, run 'Import-Module icinga-powershell-framework'.
10+
11+
At line:1 char:1 + Use-Icinga; exit Invoke-IcingaCheckMemory -CriticalPercent 99 -Warnin ... + ~~~~~~~~~~
12+
13+
\+ CategoryInfo : ObjectNotFound:
14+
(Use-Icinga:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule Invoke-IcingaCheckMemory : The term 'Invoke-IcingaCheckMemory' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
15+
16+
At line:1 char:18 + Use-Icinga; exit Invoke-IcingaCheckMemory -CriticalPercent 99 -Warnin ... + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Invoke-IcingaCheckMemory:String ) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
17+
18+
## Reason
19+
20+
This error can have multiple reasons and different solutions. Most of the time this issue is caused either by `Execution Policies` and/or PowerShell files being blocked on the system. It does how ever mean the installation of the specific PowerShell module itself is fine and just some smaller tweaks are required.
21+
22+
## Solutions
23+
24+
### Import the Module
25+
26+
Sometimes this issue can already be resolved by simply importing the module once with a user. In that case, all files are properly read and the module is available on the system. The corresponding module is always named within the exception messages. In this example, it is the `icinga-powershell-framework`. To import this module we simply run
27+
28+
```powershell
29+
Import-Module 'icinga-powershell-framework';
30+
```
31+
32+
In case no error occurs, we can continue this step for all affected modules and check if Icinga can now execute the commands. If not, please read on.
33+
34+
### Unblock PowerShell Files
35+
36+
Sometimes even with proper defined `Execution Policies` the execution of plugins or commands could fail. To resolve this, you can simply unblock the files of a specific folder. In this example we will assume that that modules are installed into `C:\Program Files\WindowsPowerShell\Modules` and our module name is `icinga-powershell-framework`.
37+
38+
```powershell
39+
Get-ChildItem `
40+
-Path 'C:\Program Files\WindowsPowershell\Modules\icinga-powershell-framework' `
41+
-Recurse | Unblock-File
42+
```
43+
44+
Repeat this for all affected modules and try again to execute plugins by Icinga. If the issue is not resolved, please read on
45+
46+
### Configure Execution Policies
47+
48+
Within the [Microsoft Docs](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy) there is a very detailed article on how `Execution Policies` work. In general these policies define on how PowerShell scripts and modules are being handled and if they can be executed by users.
49+
50+
Before doing any modifications on `Execution Policies`, please check your internal security guidelines which rules should apply.
51+
52+
To check on how the current `Execution Policies` are configured on the host, you can run this:
53+
54+
```powershell
55+
Get-ExecutionPolicy -List
56+
```
57+
58+
There are different scopes available to set policies for:
59+
60+
* **MachinePolicy**: Set by a Group Policy for all users of the computer
61+
* **UserPolicy**: Set by a Group Policy for the current user of the computer
62+
* **Process**: Affects only the current PowerShell session
63+
* **CurrentUser**: Affects only the current user
64+
* **LocalMachine**: Default scope that affects all users of the computer
65+
66+
For each scope, you can define a policy on how modules and scripts are checked and possibly blocked:
67+
68+
* **AllSigned**: Requires that all scripts and configuration files are signed by a trusted publisher, including scripts written on the local computer
69+
* **Bypass**: Nothing is blocked and there are no warnings or prompts
70+
* **Default**: Sets the default execution policy. Restricted for Windows clients or RemoteSigned for Windows servers
71+
* **RemoteSigned**: Requires that all scripts and configuration files downloaded from the Internet are signed by a trusted publisher. The default execution policy for Windows server computers
72+
* **Restricted**: Doesn't load configuration files or run scripts. The default execution policy Windows client computers
73+
* **Undefined**: No execution policy is set for the scope. Removes an assigned execution policy from a scope that is not set by a Group Policy. If the execution policy in all scopes is Undefined, the effective execution policy is Restricted
74+
* **Unrestricted**: Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs
75+
76+
In case your internal security policy defines that PowerShell scripts and modules require being **RemoteSigned**, you can do this for yourself as Icinga is not shipping signed modules. To do so, please have a look on the [Microsoft Docs About Signing](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_signing).
77+
78+
To modify the `Execution Policies`, you have to run the PowerShell as Administrator and provide the `Scope` as well as the `Execution Policy`:
79+
80+
```powershell
81+
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
82+
```
83+
84+
Once applied, you can try to use `Import-Module` again for the affected PowerShell module and checking your Icinga again if checks are now properly executed.

Diff for: doc/knowledgebase/IWKB000005.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Icinga Knowledge Base - IWKB000005
2+
3+
## Short Message
4+
5+
powershell.exe : Failed to start service 'Icinga PowerShell Service (icingapowershell)'.
6+
7+
## Example Exception
8+
9+
powershell.exe : Failed to start service 'Icinga PowerShell Service (icingapowershell)'.
10+
11+
At C:\Program
12+
Files\WindowsPowerShell\Modules\icinga-powershell-framework\lib\core\framework\Restart-IcingaService.psm1:29 char:9
13+
14+
\+ powershell.exe -Command {
15+
16+
\+ ~~~~~~~~~~~~~~~~~~~~~~~~~
17+
18+
\+ CategoryInfo : OpenError: (System.ServiceProcess ServiceController:ServiceController) [Restart-Service], ServiceCommandException
19+
20+
\+ FullyQualifiedErrorId :
21+
StartServiceFailed,Microsoft.PowerShell.Commands.RestartServiceCommand
22+
23+
### Event Log Entry
24+
25+
error-event (Source: Icinga
26+
PowerShell Service, Event ID 0):
27+
28+
Service cannot be started. System.ComponentModel.Win32Exception
29+
(0x80004005): The system cannot find the file specified
30+
31+
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo
32+
startInfo)
33+
34+
at icinga_service.src.classes.Agent.StartAgent()
35+
36+
at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object
37+
state)
38+
39+
## Reason
40+
41+
The `icingapowershell` service of the `Icinga for Windows` solution is unable to locate `powershell.exe`. The service is using `powershell.exe` natively without any directory configuration and looking up the `PATH` variable which normally includes a path like `C:\Windows\System32\WindowsPowerShell\v1.0` which contains the required `powershell.exe`
42+
43+
## Solution
44+
45+
To resolve this issue, ensure that your `PATH` environment variable is containing a directory which inherits a `powershell.exe`. By default, this should be `C:\Windows\System32\WindowsPowerShell\v1.0`.
46+
47+
You can check this by opening a PowerShell by running the following command:
48+
49+
```powershell
50+
($ENV:Path).Split(';')
51+
```
52+
53+
If there is no directory listed containing a `powershell.exe`, you will have to add this path manually. You can either use the UI for this or modify and run the following PowerShell code within an Administrator shell to add a new path permanently to the `PATH` variable by modifying the registry:
54+
55+
```powershell
56+
# The variable containing the folder we want to include
57+
$PathDir = 'please enter the path here';
58+
59+
# Read PATH from registry
60+
$CurrentPath = (Get-ItemProperty `
61+
-Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' `
62+
-Name 'PATH'
63+
).path;
64+
65+
# Add our defined path to the CurrentPath variable
66+
$CurrentPath = [string]::Format('{0};{1}', $CurrentPath, $PathDir);
67+
68+
# Write the modified Path into the registry
69+
Set-ItemProperty `
70+
-Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' `
71+
-Name 'PATH' `
72+
-Value $CurrentPath;
73+
```
74+
75+
Now open a new PowerShell session again and check of the new directory was added:
76+
77+
```powershell
78+
($ENV:Path).Split(';')
79+
```
80+
81+
Once the directory is there, restart the `icingapowershell` service by running
82+
83+
```powershell
84+
Restart-Service 'icingapowershell'
85+
```
86+
87+
Now the error should be resolved the the service should be running.

0 commit comments

Comments
 (0)