Powershell – How to put laptop to sleep with powershell/vbs/wmi/…

electrical-powerpowershellwmi

I'd like to be able to put my laptop to sleep from the command line. According to Microsoft, the Win32_Battery WMI class has a SetPowerState method that looks like it should be able to do this, however, on several laptops I've tried, I just get different errors indicating this method is not implemented or other various failures:

-> gwmi Win32_Class
Get-WmiObject : Retrieving the COM class factory for component with CLSID {EB87E1BD-3233-11D2-AEC9-00C04FB68820} failed
 due to the following error: 80040154.
At line:1 char:5
+ gwmi <<<<  Win32_Class
    + CategoryInfo          : InvalidOperation: (:) [Get-WmiObject], COMException
    + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

Do any laptops implement this? Know another way to do this? Doesn't have to be WMI, anything that puts the machine in the same low power state as shutting the lid does on most laptops.

Best Answer

You may use the following commands in a PowerShell prompt:

Add-Type -Assembly System.Windows.Forms
[System.Windows.Forms.Application]::SetSuspendState("Suspend", $false, $true)