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

Monitor scheduled windows task

Votes:

0

We need to monitor a scheduled task created on a server can we do it by PRTG?

custom tasks wmi

Created on Aug 17, 2018 3:27:59 PM



4 Replies

Votes:

0

Daniel,

We cannot monitor the scheduled task itself natively. You might be best by creating a PowerShell script to poll for the data, and have that dump into PRTG via a custom script.

Depending on what the task does, we can monitor for services or processes it invokes.

Benjamin Day
Paessler Support

Created on Aug 18, 2018 6:49:16 AM by  Benjamin Day [Paessler Support] (1,441) 2 1



Votes:

0

Created on Jul 5, 2019 6:35:43 AM



Votes:

0

Here's a shorter PowerShell script I created based on the details in the link above.

# Parameters
param (
  [parameter(Mandatory=$true,position=0)] 
  [string] 
  $Server,

  [parameter(Mandatory=$true,position=1)] 
  [string] 
  $TaskName,

  [parameter(position=3)] 
  [string] 
  $Folder = '\'
)


# Main

try {
    # Get task status
    $Schedule = New-Object -ComObject 'Schedule.Service'
    $Schedule.connect($Server)
    $FolderRef = $Schedule.getfolder($Folder)
    $Task = $FolderRef.GetTasks(1) | Where-Object {$_.name -eq $TaskName}

    $TaskEnabled = $Task.enabled
    $TaskLastRunHours = [math]::round($(New-TimeSpan -Start $([datetime]$Task.lastruntime) -End $(Get-Date)).TotalHours,0)
    $TaskLastResult = $Task.lasttaskresult

    # Create PRTG response
    $Message = "The scheduled task `'$TaskName`' last ran $TaskLastRunHours hour(s) ago with a result of $TaskLastResult."

    $Channels = @()

    $Channels += [pscustomobject]@{
        'channel'="Task Enabled";
        'value'= [int]($TaskEnabled)
    }

    $Channels += [pscustomobject]@{
        'channel'="Hours since last run";
        'value'= $TaskLastRunHours
    }

    $Channels += [pscustomobject]@{
        'channel'="Last run result";
        'value'= $TaskLastResult
    }

    $Result = [pscustomobject]@{
        result = $Channels;
        text = "$Message"
    }
    $PRTGResult = [pscustomobject]@{prtg = $Result}
    $PRTGResult | ConvertTo-Json -Depth 3
}
catch {
    $Result = [pscustomobject]@{
        error = '1';
        text = "$HealthCheckURL Error at line $($_.InvocationInfo.ScriptLineNumber): $_     $($_.Exception)"
    }
    $PRTGResult = [pscustomobject]@{prtg = $Result}
    $PRTGResult | ConvertTo-Json
}

Created on Oct 18, 2019 12:58:23 AM



Votes:

0

Dezdez,

Have you considered submitting this for ScriptWorld?

Submit your script to ScriptWorld

Thanks!

Benjamin Day
Paessler Support

Created on Oct 21, 2019 9:04:20 PM by  Benjamin Day [Paessler Support] (1,441) 2 1




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.