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

PRTG Custom Sensor - Powershell - Functions not recognized?

Votes:

0

I have written a Powershell script with a defined function. It runs just fine when executed in a powershell window, but when PRTG runs it, it says the command (the function I defined later in the script) is not recognized. Is there some restriction on how functions work in Powershell when used by PRTG?

Here is the beginning of my code: (Get-ScheduledTask is a function I defined right after this code)

Param(
    [string]$MyComputerName,
    [string]$MytaskName
)

$task = ((Get-ScheduledTask -ComputerName $MyComputerName) | select TaskName, LastRunTime | Where-Object {$_.TaskName -eq $MytaskName})

write-host (New-Timespan -Start $task.LastRunTime).Minutes,":OK"

custom-sensor powershell prtg

Created on Jul 18, 2016 8:10:03 PM

Last change on Jul 19, 2016 8:11:34 AM by  Torsten Lindner [Paessler Support]



2 Replies

Accepted Answer

Votes:

0

Hello,

Thank you very much for your KB-Post. First, please try defining the funcition before actually referring to it in your script code. And then please also try the following included at the beginning of the script:

Import-Module Microsoft.PowerShell.Management; Import-Module Microsoft.PowerShell.Utility

Does it work then?

best regards.

Created on Jul 19, 2016 11:18:27 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Thanks for the suggestion(s). I moved the function above the script code calling the function and it works now.

Strange.

Created on Jul 19, 2016 4:50:38 PM




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.