Stop Computer - PowerShell


Overview

The Stop-Computer cmdlet gracefully shuts down the computer it’s run on. It prompts for confirmation by default, but this can be suppressed.

Syntax

Stop-Computer [-Confirm] [-WhatIf] [-Force] [-DisableAutomaticRestart] [-RestartDelay <TimeSpan>]

Options/Flags

  • -Confirm: Prompts for confirmation before stopping the computer.
  • -WhatIf: Shows what would happen if the command were run without actually executing it.
  • -Force: Stops the computer without prompting for confirmation.
  • -DisableAutomaticRestart: Prevents the computer from automatically restarting after a system update.
  • -RestartDelay: Sets the time in seconds the computer will wait before restarting after a system update (valid range: 0-86400).

Examples

Example 1: Stop the computer with confirmation

Stop-Computer

Example 2: Stop the computer without confirmation

Stop-Computer -Force

Example 3: Gracefully stop the computer with 1-minute delay

Stop-Computer -DisableAutomaticRestart -RestartDelay 60

Common Issues

  • Confirmation can be annoying if the command is automated. Use -Force to avoid it.
  • If the -DisableAutomaticRestart flag is not used, the computer may restart automatically after a system update, even if the -Force flag is used.

Integration

Stop-Computer can be used in conjunction with other commands to automate complex tasks. For example:

Restart-Computer -Force && Stop-Computer -Force

This command would restart the computer and then immediately shut it down.