Back to OP5 Monitor FAQ

Execute PowerShell scripts

This procedure is unsupported Copied

Articles in the “Unsupported Community Documents” space are not supported by ITRS support.

Version Copied

This article was written for version 7.0 of Monitor, it could work on both lower and higher version if nothing else is stated.

Introduction Copied

This how-to will show you how to execute a powershell script via the op5 Agent.

Prerequisites Copied

Create powerShell script Copied

First we need to create a powershell script or use an existing one. In this example we will use a simple Hello World script.

The script that we will use is

hello.ps1

 Write-Host "Hello World! `n"

This will be placed in the script folder within the agent installation folder, in this case in: C:\Program Files\op5\NSClient++\scripts\

Save the script as hello.ps1

Add the script to op5 Agent Copied

To make the op5 Agent aware of the script and how it should be executed we need to add a handler for it in the agent configuration.

Open the file custom.ini located in C:\Program Files\op5\NSClient++\ and add the following rows

[NRPE Handlers]hello=cmd /c echo scripts\hello.ps1; exit $LastExitCode | powershell.exe -noprofile -nologo -command -

Set ExecutionPolicy Copied

Due to restrictions in powershell we are not allowed to run this file without changing the execution policy for powershell scripts.

In this example we will change the policy to unrestricted but this is not recommended for normal use. For more information about Execution Policy see http://technet.microsoft.com/library/hh847748.aspx.

Open powershell prompt as administrator and run

PS C:\Windows\system32> Set-ExecutionPolicy unrestricted

Answer Y on the question.

OP5 Monitor - Execute PowerShell scripts

Run script from op5 Monitor console Copied

This step is not necessary, but can be good before continuing just to make sure everything is working before change the configuration.

Log in to op5 Monitor via console or SSH.

Run the following command to test the powershell script

## /opt/plugins/check_nrpe -H 192.168.1.198 -c hello

If everything is working you should get the response “Hello World!”

Adding script to a host Copied

Go to the configuration of a host in op5 Monitor and add a new service.

  1. Enter a Service Description of you choice

  2. Select check_nrpe as check_command

  3. Enter hello as check_command_args

    OP5 Monitor - Execute PowerShell scripts

  4. Save the configuration.

["Geneos"] ["FAQ"]

Was this topic helpful?