community.windows icon indicating copy to clipboard operation
community.windows copied to clipboard

Set "Enable All Tasks History" in Task Scheduler

Open davetapley opened this issue 3 years ago • 1 comments

SUMMARY

Task Scheduler has a "Enable All Tasks History" setting ⬇️, but win_scheduled_task_module doesn't allow it to be set.

image

ISSUE TYPE
  • Feature Idea
COMPONENT NAME

win_scheduled_task_module

ADDITIONAL INFORMATION

It appears this can be set with PowerShell:

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

I can make a PR if it would be welcome?

davetapley avatar Dec 18 '20 02:12 davetapley

This is a tricky one as the win_scheduled_task module is designed to work for individual tasks and not configuration for task scheduler itself. I would personally recommend it goes into it's own module but having a single module just for this option seems a bit overkill IMO.

If anything I would recommend it's done as an example in the win_scheduled_task documentation. You can either use the .NET method and have some idempotency added like so

- win_shell: |
    $logName = 'Microsoft-Windows-TaskScheduler/Operational'
    $log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName

    if ($log.IsEnabled) {
        $false
    } else {
        $log.IsEnabled = $true
        $log.SaveChanges()
        $true
    }
  register: schedule_history
  changed_when: schedule_history.stdout | trim | bool

or just have a simple blanket setting

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

jborean93 avatar Jan 25 '21 02:01 jborean93