PowerShell/Examples/Create-ShutdownTask

# This script creates a task to automatically shut down the system 2 hours after logon.

# Time may be adjusted by altering PT2H below.
# PT1H = 1 Hour
# PT60M = 60 Minutes

function Create-ShutdownTask {
    $action = New-ScheduledTaskAction -Execute "shutdown" -Argument "/s"
    $trigger = New-ScheduledTaskTrigger -AtLogOn
    $trigger.Delay = "PT2H"

    Register-ScheduledTask -TaskName "Shutdown" -TaskPath "\" -Action $action -Trigger $trigger
}

Create-ShutdownTask

See Also

edit