Skip to content

shutdown_toggle.ps1

Corey Watson edited this page Dec 1, 2025 · 1 revision

shutdown_toggle.ps1

Shutdown Toggle with Warning.

Overview

Schedules a system shutdown with a warning message, or cancels an existing scheduled shutdown if one is already pending. Acts as a toggle - run once to schedule, run again to cancel.

Purpose

This script provides a safe way to remotely schedule or cancel system shutdowns with user warnings. The toggle behavior allows technicians to easily cancel an accidental shutdown by simply running the script again.

Prerequisites

  • Windows 10/11 or Windows Server
  • Administrator privileges
  • shutdown.exe (standard Windows component)

Configuration

Required Inputs

  • $shutdownTime : Time in seconds before shutdown (default: 60)

Behavior

  1. Checks if a shutdown is already scheduled
  2. If scheduled: Cancels the pending shutdown
  3. If not scheduled: Schedules a new shutdown with warning message
  4. User sees on-screen countdown before shutdown

Security Notes

  • No secrets in logs
  • Shutdown can be canceled by running script again

Exit Codes

  • 0 = Success (shutdown scheduled or canceled)
  • 1 = Failure

Example Output

Scheduling a Shutdown

[ INPUT VALIDATION ]
--------------------------------------------------------------
Shutdown Time : 60 seconds

[ CHECKING SHUTDOWN STATUS ]
--------------------------------------------------------------
Pending Shutdown : None detected

[ SCHEDULING SHUTDOWN ]
--------------------------------------------------------------
Command : shutdown /s /t 60
Warning message displayed to user
Shutdown scheduled in 60 seconds

[ FINAL STATUS ]
--------------------------------------------------------------
Result : SHUTDOWN SCHEDULED
Run this script again to cancel

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Canceling a Shutdown

[ INPUT VALIDATION ]
--------------------------------------------------------------
Shutdown Time : 60 seconds

[ CHECKING SHUTDOWN STATUS ]
--------------------------------------------------------------
Pending Shutdown : DETECTED

[ CANCELING SHUTDOWN ]
--------------------------------------------------------------
Executing : shutdown /a
Shutdown canceled successfully

[ FINAL STATUS ]
--------------------------------------------------------------
Result : SHUTDOWN CANCELED

[ SCRIPT COMPLETED ]
--------------------------------------------------------------

Version History

  • v1.0.0 (2024-12-01) - Initial release - migrated from SuperOps

Links

Clone this wiki locally