---
title: "Execute PowerShell scripts"
description: "Executing PowerShell scripts via the op5 Agent involves creating a script, configuring the agent, and adjusting PowerShell execution policies. The process includes testing the script from the op5 Monitor console and adding it as a service check on a host."
url: "https://docs.itrsgroup.com/docs/faq/op5/360020054854-op5-monitor-execute-powershell-scripts/index.html"
---
## This procedure is unsupported

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

## Version

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

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

## Prerequisites

- Working installation of op5 Agent
- Working installation of op5 Monitor

## Create powerShell script

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

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

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](https://docscdn.itrsgroup.com/faq/images/op5/360020054854-12190637-ps_execpolicy.png)

## Run script from op5 Monitor console

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

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](https://docscdn.itrsgroup.com/faq/images/op5/360020054854-12190637-nacoma_nrpe.png)

4. Save the configuration.


