Skip to content

Instantly share code, notes, and snippets.

@boertel
Created October 27, 2020 16:26
Show Gist options
  • Save boertel/47bb5c7cd66a405cdcf0168068db055b to your computer and use it in GitHub Desktop.
Save boertel/47bb5c7cd66a405cdcf0168068db055b to your computer and use it in GitHub Desktop.
Task Scheduler for power mgmt 07:00 to 22:00
$DateTimeNow = Get-Date
$DateTimeMorning = Get-Date -Hour 7 -Minute 0
$DateTimeNight = Get-Date -Hour 22 -Minute 0
# 07:00 < now < 22:00
if ($DateTimeNow.TimeOfDay -gt $DateTimeMorning.TimeOfDay -and $DateTimeNow.TimeOfDay -lt $DateTimeNight.TimeOfDay) {
powercfg.exe /S SCHEME_MIN
} else {
powercfg.exe /S SCHEME_BALANCED
SCHTASKS /Create /F /SC ONLOGON /TN "logon_check" /TR "PowerShell.exe -ExecutionPolicy Bypass -File C:\subscripts\check_power.ps1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment