New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


How can I use PowerShell scripts with PRTG's 'Execute Program' notification?

Votes:

0

Your Vote:

Up

Down

Can you give an example of how I can create a PowerShell (*.ps1) script to execute custom notifications in PRTG?

exe-script notifications powershell prtg ps1

Created on Apr 20, 2011 12:32:44 PM by  Daniel Zobel [Paessler Support]

Last change on Apr 20, 2011 12:43:15 PM by  Daniel Zobel [Paessler Support]



4 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 12 or later, as well as to previous (deprecated) versions

Demo 'Powershell' Notification for PRTG Network Monitor

PRTG Network Monitor is a network monitoring tool that offers multiple possibilities to send notifications on important events, for example when a device or individual sensors are down, thresholds are breached, devices fail to respond in a timely matter, etc.

If the built-in notification types do not meet your needs PRTG allows you to create your own notification mechanisms using script files like batch files or powershell scripts.

The following powershell demo script has a very basic functionality to demonstrate how powershell scripts work in PRTG. It simply writes the current date/time to a file. You have to pass the filename as parameter to the script. This script may help you troubleshooting your own powershell notifications.

The script must be copied into the notifications\exe sub folder of your PRTG core server program directory (of each node, if in a cluster).

# Demo 'Powershell' Notification for PRTG Network Monitor
# Writes current date/time into a file
#
# How to use it:
#
# Create a new 'Execute Program' notification in PRTG 
# and from the 'Program file' drop-down, select 'Demo Exe Notifcation - OutFile.ps1'.
# The 'Parameter' section consists of one parameter:
#
# - Filename
#
# e.g.
#
#        'C:\temp\test.txt'
#
# Note that the directory specified must exist.
# Adapt error handling to your needs.
# This script comes without any warranty or support.


if ($Args.Count -eq 0) {

  #No Arguments. Filename must be specified.

  exit 1;
 }elseif ($Args.Count -eq 1){


  $Path = split-path $Args[0];
 
  if (Test-Path $Path)   
  {
    $Text = Get-Date;
    $Text | out-File $Args[0];
    exit 0;
 
  }else
  {
    # Directory does not exist.
    exit 2;
  }
}

Security Issues

It's a good practice to not enter passwords, parameters, etc. directly into your script. Instead, you can use the parameter field in PRTG to hand over these values to your script when calling it.

Information about signing Powershell scripts and the Execution Policy for scripts can be found in the following external resources:

  • PowerShell Script Signing
  • PowerShell Security
    For Powershell notifications, bear in mind, it depends on which version (32bit or 64bit) of the PRTG Core Service is running, if either the 32bit or the 64bit Powershell are used.

Created on Apr 20, 2011 12:42:46 PM by  Daniel Zobel [Paessler Support]

Last change on Feb 26, 2014 2:59:30 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Many of the placeholder parameters available to be passed from PRTG to custom notification scripts need to be single-quoted to be passed to the script correctly.

'%location' '%host' '%shortname'

Double-quotes don't seem to work - probably an artifact of whatever command string they're building to execute the script + params.

Created on Oct 31, 2012 7:29:43 PM by  jsanders (0)



Votes:

0

Your Vote:

Up

Down

Hi,

Is it possible to use the built in SMTP relay server for notifications from a script like this, or does an external SMTP relay server have to be used?

Created on Dec 14, 2016 8:40:33 AM by  Nav (0) 1



Votes:

0

Your Vote:

Up

Down

Hi,

There is no SMTP relay used, the PowerShell will be executed on the PRTG Core Server itself.

Created on Dec 14, 2016 9:11:11 AM by  Dariusz Gorka [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.