Suspend-Computer
Puts one or more computers into a low-power state (sleep or hibernate).
Suspend-Computer completes the *-Computer power lifecycle family
(Stop-Computer, Restart-Computer) with the missing suspend state. It was
proposed to the PowerShell team in
PowerShell#28164;
the Cmdlets Working Group recommended delivering it as a community module on
the PowerShell Gallery, which is exactly what Bsn.SystemManagement is.
Syntax
Suspend-Computer [[-ComputerName] <string[]>] [-Hibernate] [-Force]
[-After <int>] [-WhatIf] [-Confirm]
Platform support
| Platform | Sleep | Hibernate |
|---|---|---|
| Windows | SetSuspendState (powrprof.dll P/Invoke) |
SetSuspendState(hibernate: true) |
| Linux | systemctl suspend (loginctl fallback) |
systemctl hibernate (requires the disk state in /sys/power/state) |
| macOS | pmset sleepnow |
Not supported |
Parameters
- ComputerName - target computers, defaulting to the local computer. Accepts pipeline input. Remote computers require PowerShell remoting (WinRM or SSH); the module does not need to be installed remotely.
- Hibernate - hibernate (S4) instead of sleep (S3 / Modern Standby).
- Force - skip the confirmation prompt and request a forced (critical) suspend.
- After - suspend after the specified number of seconds have elapsed on the target computer (the countdown starts when the command reaches it). The default (0) suspends immediately. While the countdown runs, press Ctrl+C to cancel the pending suspension.
Examples
Suspend-Computer -WhatIf
Shows what would happen without suspending anything.
Suspend-Computer
Prompts for confirmation, then puts the local computer to sleep.
Suspend-Computer -Hibernate -Force
Hibernates the local computer immediately, without a confirmation prompt.
Suspend-Computer -After 60
Suspends the local computer after 60 seconds, leaving a minute to save your work. Press Ctrl+C during the countdown to cancel.
Suspend-Computer -ComputerName MEDIA-01 -After 300 -Confirm:$false
Suspends the remote computer MEDIA-01 five minutes after the command reaches it.
'WORKSTATION-07', 'WORKSTATION-12' | Suspend-Computer -Confirm:$false
Suspends two remote computers over PowerShell remoting without a prompt.
Notes
The Windows implementation calls the documented
SetSuspendState
API directly, avoiding both the undocumented
rundll32.exe powrprof.dll,SetSuspendState hack and loading WinForms.