Closed hartleyj closed 4 years ago
Tempted to say that this should be a default behaviour, and switch options to disable those. I’d expect the command to run, by default, regardless of battery state.
Agreed. This PR changes the default behavior.
No allowances are made for changing this new default with a switch option, however.
Updated Invoke-ScheduledTask.ps1 to add "-StartIfOnBattery -ContinueIfGoingOnBattery" parameters to New-ScheduledJobOption
Default behavior of scheduled tasks is to start when on AC power, causing Invoke-CommandAs to silently fail when run on a system running on battery power.
Added 'StartIfOnBattery' to allow scheduled tasks to run when on battery power, and 'ContinueIfGoingOnBattery' to allow for long-running script blocks to continue running after transitioning from AC to battery power.