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


PRTG Custom Sensor - Powershell - Functions not recognized?

Votes:

0

Your Vote:

Up

Down

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 by  Peter Bollwerk (80) 1 1

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



2 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

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 by  Peter Bollwerk (80) 1 1



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.