The last pull request by hartleyj fixed running on battery power when running as a job, but not when running as a task, so it still didn't work for running with -AsSsytem, -AsInteractive, -AsUser, or -AsGMSA. Fixed that by adding a New-ScheduledTaskSettingsSet to $TaskParameters and setting -AllowStartIfOnBatteries and -DontStopIfGoingOnBatteries.
The last pull request by hartleyj fixed running on battery power when running as a job, but not when running as a task, so it still didn't work for running with -AsSsytem, -AsInteractive, -AsUser, or -AsGMSA. Fixed that by adding a New-ScheduledTaskSettingsSet to $TaskParameters and setting -AllowStartIfOnBatteries and -DontStopIfGoingOnBatteries.