Search code examples
powershellscheduled-tasks

How can I `Enable All Tasks History` in PowerShell?


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

See also https://stackoverflow.com/questions/11013132/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).


Solution

  • 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/