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 ?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With