Get Scheduled task statistics

Welcome Forums General PowerShell Q&A Get Scheduled task statistics

This topic contains 4 replies, has 3 voices, and was last updated by

2 years, 7 months ago.

  • Author
  • #37636

    Points: 20
    Rank: Member

    Hi can do most of what i want here, however im struggling to get the "Run Start" and "Run End" parameters to show through powershell, just lack of knowledge i guess.

    Get-ScheduledTask | Get-ScheduledTaskInfo

    gives me the below

    LastRunTime : 07/04/2016 10:54:54
    LastTaskResult : 267009
    NextRunTime :
    NumberOfMissedRuns : 0
    TaskName : CacheTask
    TaskPath : \Microsoft\Windows\Wininet\
    PSComputerName :

    but i would like to see the "Run Start" and "Run End" parameters like you do when you open up the Task scheduler GUID

    Edit actually Last run time would be "Run Start" so Just "Run End" needed really


  • #37637

    Points: 0
    Rank: Member

    That information doesn't appear to be available on the CIM class called by the cmdlet

  • #37640

    Points: 0
    Rank: Member

    If you're referring to the information in the History tab of the Task Scheduler GUI, it's getting that stuff from the event log (specifically: Microsoft-Windows-TaskScheduler/Operational).

  • #37664

    Points: 20
    Rank: Member

    thanks Richard, just needed someone else to sanity check for me

    Dave thats perfect, i should be able to get what i need from there, thanks

  • #37724

    Points: 20
    Rank: Member

    just an update to this guys i found this script below, couldnt really get it working properly though, i can see the events start & stop with the relevant 200/201 codes but script just refuses to pick this up, tried on v2 & v4 PS


     .\Get-taskruns.ps1 -TaskName "\EV-Clear-State" -computername PCNAME
    Started                       Stopped                       Elapsed                       ReturnCode
    -------                       -------                       -------                       ----------
    09/01/2016 06:45:00
      [String]$ComputerName = (& hostname) 
    $startCode = 200 
    $stopCode = 201 
    $filter = @" 
        *[System[(EventID=$startCode or EventID=$stopCode)] and EventData[Data[@Name="TaskName"]="$TaskName"]] 
    $events = get-winevent -Oldest -FilterXML $filter -ComputerName $ComputerName 
    $instanceRegex = [regex]'{([^}]+)' 
    $returnCodeRegex = [regex]'return code (\d+)' 
    $runs = @{} 
    $events | % { 
        $_.message -match $instanceRegex | Out-Null 
        $guid = $matches[1] 
        if (-not $runs.Contains($guid)) { 
            $run = New-Object System.Object 
            $run | Add-Member -type NoteProperty -name Started -value $null 
            $run | Add-Member -type NoteProperty -name Stopped -value $null 
            $run | Add-Member -type NoteProperty -name Elapsed -value $null 
            $run | Add-Member -type NoteProperty -name ReturnCode -value $null 
            $runs[$guid] = $run 
        } else { 
            $run = $runs[$guid]; 
        if ($ -eq $startCode) { 
            $run.Started = $_.timecreated; 
        elseif ($ -eq $stopCode) { 
            $run.Stopped = $_.timecreated; 
            $_.message -match $returnCodeRegex | Out-Null 
            $run.ReturnCode = $matches[1] 
            $run.elapsed = ($run.Stopped - $run.Started) 
    $runs.values | Sort Started -Descending

The topic ‘Get Scheduled task statistics’ is closed to new replies.