Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-scheduled task to see history for more than last run

when i run

Get-ScheduledTask -TaskName "ttasskkk" | Get-ScheduledTaskInfo

I receive info about last run time only. how to use PS to see results from last 7 runs or more ?

like image 952
greenszpila Avatar asked Oct 15 '25 14:10

greenszpila


1 Answers

The history of scheduled tasks is not available in the Get-ScheduledTask cmdlet. What you can do is use Get-WinEvent to check the log Microsoft-Windows-TaskScheduler/Operational for the history of the task.

$TaskName = "\MyCoolTask"

# if your scheduled task is nested into a folder named 'Automations'
# $TaskName = "\Automations\MyCoolTask"

$events = @(
     Get-WinEvent  -FilterXml @"
     <QueryList>
      <Query Id="0" Path="Microsoft-Windows-TaskScheduler/Operational">
       <Select Path="Microsoft-Windows-TaskScheduler/Operational">
        *[EventData/Data[@Name='TaskName']='$( $TaskName )']
       </Select>
      </Query>
     </QueryList>
"@  -ErrorAction Stop -MaxEvents 2
)
$events
like image 196
jrider Avatar answered Oct 18 '25 02:10

jrider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!