Hibernate or Standby via PowerShell

by Mar 1, 2022

In the previous tip we illustrated that while it is hard to directly access the Windows Power Management API, there are other API calls that can do this for you. Here is a chunk of code that lets you shut down a Windows system to a desired power management state, i.e. you can hibernate it and put it into a no-energy-consumption state:

# use the built-in pwmgmt support in Windows Forms
Add-Type -AssemblyName System.Windows.Forms

# define the power status you want to enable
$PowerState = [System.Windows.Forms.PowerState]::Hibernate

# allow or refuse force to be applied
$Force = $false

# turn off wake off capabilities as well
$DisableWake = $false

# apply the setting:
[System.Windows.Forms.Application]::SetSuspendState($PowerState, $Force, $DisableWake)


Twitter This Tip! ReTweet this Tip!