PowerShell - Changing the state of a computer (sleep, hibernate, shutdown, restart)

1 min read · Updated 20 September 2024

Did this guide help you? You can support me by subscribing to the channel, sharing it, disabling your ad blocker or making a donation. Thank you!

Hello,

A new article to show how to change the state of a computer (sleep, hibernate, shutdown, reboot) with PowerShell.
The forced option is useful if, for example, a user session is open and prevents the action (boot…) from taking place.

# Put to sleep
Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState('Suspend', $false, $false)
# Force to sleep
Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState('Suspend', $true, $false)
# Put into hibernation
Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState('Hibernate', $false, $false)
# Force Hibernate
Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState('Hibernate', $true, $false)
# Restart
Restart-Computer
# Force restart
Restart-Computer -Force
# Stop
Stop-Computer
# Force stop
Stop-Computer -Force

Related links

Follow me on

Support me

Buy Me a Coffee at ko-fi.com

New site · Reference

The Windows directory tree

Native Windows folders, files and logs: what they are for, what they contain, with commands and Microsoft sources.

Browse the tree

New site · Reference

Group Policy settings

ADMX settings for Windows 10, 11, Server and applications: registry keys, PowerShell commands and use cases.

Browse the policies