PowerShell Scheduled Job Last Result Monitor.
The monitor checks the last result of a PowerShell Scheduled Job for error items (exceptions).
Any error observed is considered a warning condition for scheduled job with trigger(s).
Use overrides to:
Disable the monitor
Allow a number of exceptions to be considered a healthy condition.
The PowerShell script called by the Scheduled Job threw exceptions.
Log onto the affected computer as the user that created the PowerShell Scheduled Job and run the following PowerShell command to get access to the job's last result:
Get-Job -Name "name of the job" -Newest 1
gets the latest result object of a scheduled job, including the script code that ran.
This allows further investigating why the script did not complete sucessfully. Refer to the "Additional" section in case changes to the job are required.
and/or Re-run Scheduled Job
Disable or delete the PowerShell Scheduled Job
TechNet documentation regarding PSScheduledJob:
Target | Custom.TaskScheduler2.Task | ||
Parent Monitor | System.Health.AvailabilityState | ||
Category | AvailabilityHealth | ||
Enabled | True | ||
Alert Generate | True | ||
Alert Severity | MatchMonitorHealth | ||
Alert Priority | Normal | ||
Alert Auto Resolve | True | ||
Monitor Type | Custom.Windows.ScheduledTaskV2.PSScheduledJob.LastResult_Error.MonitorType | ||
Remotable | False | ||
Accessibility | Public | ||
Alert Message |
| ||
RunAs | Default |
<UnitMonitor ID="Custom.Windows.ScheduledTaskV2.PSScheduledJob.LastResult_Error.Monitor" Accessibility="Public" Enabled="true" Target="Custom.TaskScheduler2.Task" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="false" Priority="Normal" TypeID="Custom.Windows.ScheduledTaskV2.PSScheduledJob.LastResult_Error.MonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Custom.Windows.ScheduledTaskV2.PSScheduledJob.LastResult_Error.Monitor.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Data/Context/Property[@Name='Path']$</AlertParameter1>
<AlertParameter2>$Data/Context/Property[@Name='Name']$</AlertParameter2>
<AlertParameter3>$Data/Context/Property[@Name='User']$</AlertParameter3>
<AlertParameter4>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</AlertParameter4>
<AlertParameter5>$Data/Context/Property[@Name="PSJobErrorCount"]$</AlertParameter5>
<AlertParameter6>$Data/Context/Property[@Name="PSJobErrorContent"]$</AlertParameter6>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="NoError" MonitorTypeStateID="NoError" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Warning"/>
</OperationalStates>
<Configuration>
<ComputerName>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</ComputerName>
<TaskPath>$Target/Property[Type="SchTaskLib!Custom.Windows.TaskSchedulerTask"]/TaskPath$</TaskPath>
<!-- by default do not tolerate any errors -->
<maxErrorCount>0</maxErrorCount>
<WindowsTasks>$Target/Property[Type="Custom.TaskScheduler2.Task"]/WinTasksDiscovered$</WindowsTasks>
<Debug>false</Debug>
<TimeoutSeconds>300</TimeoutSeconds>
</Configuration>
</UnitMonitor>