What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Powershell script and sensor

Votes:

0

Hi, i have a powershell script that returns two values "OK!" and "Failure". How can i now use it in the PRTG EXE/script sensor?

$dir = "myDirectory"
$filter = "*.log"
$searchstring = "Status"

$latestfile = Get-ChildItem -Path $dir -Filter $filter | Sort-Object LastAccessTime -Descending | Select-Object -First 1 

$lastlines = Get-Content -Path $latestfile.FullName -Tail 5
$sel = $lastlines | select-string -pattern $searchstring

If ($sel -eq $null)
{ 
    Write-Host "Failure"
    Exit 2
}
Else
{ 
    Write-Host "OK!"
    Exit 0 
}

Thanks

powershell prtg sensor

Created on Oct 22, 2015 2:02:43 PM

Last change on Oct 22, 2015 2:34:08 PM by  Torsten Lindner [Paessler Support]



1 Reply

Votes:

0

Hello,
we appreciate your inquiry.

The described output for the two possible formats are described here.
Please note that the script will be ran on the Probe where the sensor was set-up, for the script to "monitor" remote hosts, you will need to use powershell remoting techniques.

You can also find many examples searching for the custom-script-exe tag.

Best Regards,

Created on Oct 22, 2015 5:51:37 PM by  Luciano Lingnau [Paessler]




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.