Monitoring and Alerting Specific Scheduled Task on multiple Windows Servers

How can I perform Monitoring and Alerting Specific Scheduled Tasks on multiple Windows Servers?

The scheduled Task execution details can be queried using these:

Provider Name: Microsoft-Windows-TaskScheduler/Operational
Windows Event ID: 101
Type: Error

I wanted to monitor just specific Scheduled Tasks that are manually created by the users/admins but not the built-in ones.

Thank you.

Parents
  • If you want to monitor specific scheduled tasks, powershell SAM component would probably be your best bet.

    To filter, you would probably just swap out this:          "FALSE" {$SchTask = Get-ScheduledTask -ErrorAction Stop | Where-Object {$_.TaskName -notIn $Exclusions}}, to be an In instead of notIn.

    Then you could just provide a list of schtasks you want in the script argument line (comma seperated list)

    #Build Exclusion List
        If ([String]::IsNullOrWhiteSpace($Args) -eq $False) {
            $Exclusions = $Args
        }
    
    #Retrieve Scheduled Tasks
        Try {
            Switch ([String]::IsNullOrEmpty($Exclusions)) {
                "TRUE" {$SchTask = Get-ScheduledTask -ErrorAction Stop}
                "FALSE" {$SchTask = Get-ScheduledTask -ErrorAction Stop | Where-Object {$_.TaskName -notIn $Exclusions}}
            }
            
        } Catch {
            Write-Host "Message:  Error running scheduled task $($Error[0].Exception)"
            Exit 1
        }
    
    #Display State Count
        Write-Host "Statistic.StateReady:  $(($SchTask | Where-Object {$_.State -eq "Ready"} | Measure-Object).count)"
        Write-Host "Statistic.StateDisabled:  $(($SchTask | Where-Object {$_.State -eq "Disabled"} | Measure-Object).count)"
        Write-Host "Statistic.StateRunning:  $(($SchTask | Where-Object {$_.State -eq "Running"} | Measure-Object).Count)"
    
    #Detect Failed Jobs
        $ActiveTasks = $Schtask | Where-Object {$_.State -eq "Ready" -or $_.State -eq "Running"}
        Try {
            $ActiveTasksInfo = $ActiveTasks | Get-ScheduledTaskInfo -ErrorAction Stop
        } Catch {
            Write-Host "Message:  Error running scheduled task info $($Error[0].Exception)"
            Exit 1
        }
    #Results
        Write-Host "Statistic.ResultSuccess: $(($ActiveTasksInfo | Where-Object {$_.LastTaskResult -eq 0} | Measure-Object).Count)"
        Write-Host "Statistic.ResultError: $(($ActiveTasksInfo | Where-Object {($_.LastTaskResult) -ne 0 -and ($_.LastRunTime -gt (Get-Date).AddMonths(-1))} | Measure-Object).Count)"
        Write-Host "Message.ResultError: $(($ActiveTasksInfo | Where-Object {($_.LastTaskResult) -ne 0 -and ($_.LastRunTime -gt (Get-Date).AddMonths(-1))}).TaskName -Join ",")"
        Exit 0

  • How to implement the PowerShell script to the Nodes that are already added to the SAM?

Reply Children
No Data