Turn off “If the running task does not end when requested, force it to stop” with PowerShell

Windows scheduled tasks are used to automatically execute processes on a set schedule.

To allow a long running process to continue, even if the scheduled task would start it again before the process completion, we need to uncheck the “If the running task does not end when requested, force it to stop” option.

When we use PowerShell to create the scheduled task, in the New-ScheduledTaskSettingsSet command use the -DisallowHardTerminate option.

    $settings = New-ScheduledTaskSettingsSet `
        -AllowStartIfOnBatteries `
        -DontStopIfGoingOnBatteries `
        -StartWhenAvailable `
        -RunOnlyIfNetworkAvailable:$false `
        -ExecutionTimeLimit (New-TimeSpan -Hours 12) `
        -MultipleInstances IgnoreNew `
        -DisallowHardTerminate

Leave a comment

Your email address will not be published. Required fields are marked *