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

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make 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