Files
SnipitRepo/Windows/CreateScheduledTask.ps1
2023-05-21 17:35:15 +02:00

14 lines
1003 B
PowerShell

###############################################################
# @description: #
# Used to create a new ScheduledTask #
# The task will run as System, wil wake up from sleep #
# and will run if system is on bateriess #
# #
# @author: Bram Prieshof #
###############################################################
$action = New-ScheduledTaskAction -Execute <Command> -Argument "<Args>"
$trigger = New-ScheduledTaskTrigger -At 18:00 -Daily
$options = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -DontStopOnIdleEnd -WakeToRun
$principal = New-ScheduledTaskPrincipal -UserId "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -TaskName AutoPowerOff -Trigger $trigger -Action $action -Settings $options -Principal $principal