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


Article Comments

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,


Oct, 2015 - Permalink