How can I `Enable All Tasks History` in PowerShell?
Asked Answered
Z

2

14

In the task scheduler GUI it is easy to Enable All Tasks History

See also https://mcmap.net/q/117328/-how-can-i-enable-the-windows-server-task-scheduler-history-recording

Enable All Tasks History button in GUI

How can I Enable All Tasks History through PowerShell?

I have looked at Set-ScheduledTask and New-ScheduledTask, but nothing useful there (as far as I can see).

Zielsdorf answered 22/4, 2014 at 18:56 Comment(0)
M
20

After doing a bunch of research, I found that the History tab is just a view of a windows event log, displayed using MMC snapin. So really, all that button is doing is disabling / enabling the windows event log for the task scheduler. Here is the script to automate pushing of that button :

$logName = 'Microsoft-Windows-TaskScheduler/Operational'
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName
$log.IsEnabled=$true
$log.SaveChanges()

Sources that got me there: http://windows.microsoft.com/en-us/windows-vista/automate-tasks-with-task-scheduler-from-windows-vista-inside-out
http://www.powershellmagazine.com/2013/07/15/pstip-how-to-enable-event-logs-using-windows-powershell/

Montford answered 22/4, 2014 at 19:24 Comment(0)
F
2

From an elevated command prompt or PowerShell

wevtutil set-log Microsoft-Windows-TaskScheduler/Operational /enabled:true

Frictional answered 7/2, 2022 at 6:30 Comment(1)
Thanks. Just verified it worked on Windows Server 2019. Note that if it works there's no output but I ran Task Scheduler, disabled All Tasks History, closed it, ran this command, and reopened Task Scheduler and confirmed it was now enabled. I personally prefer this over accepted answer because it's only one line, but both are right.Education

© 2022 - 2024 — McMap. All rights reserved.