- Activate BitLocker with manage-bde, PowerShell, or WMI - Wed, Sep 20 2023
- Join Azure Active Directory with Windows 11 - Tue, Sep 12 2023
- Manage enhanced security mode in Microsoft Edge using Group Policy - Fri, Sep 8 2023
Among Windows' own means, the shutdown.exe utility comes closest to solving this task. Using the /h switch, it puts the computer into hibernate mode. This is only one of several possible energy-saving options in Windows.
Hibernate mode is usually not desired
To hibernate the PC, the OS writes the memory contents to the disk, which delays the process and, subsequently, the wake-up. In addition, you have to start the computer via the power button, as pressing a key won't wake up the computer.
Typically, sleep mode is preferred, which shutdown.exe does not support. Moreover, the utility only works for the local PC.
PsShutdown as an alternative
As an alternative, you can use PsShutdown from the Sysinternals PSTools. It offers various options and works reliably for remote PCs.
The following command suspends ("-d") the remote PC after two seconds ("-t2"):
psshutdown64.exe -d -t2 -v \\Remote-PC
It displays a message during the wait ("-v"). If you omit the -t switch, the default time before suspending the system is 20 seconds. If a remote PC isn't specified, this of course also works for the local system.
The utility supports hibernation mode ("-h"), shutdown ("-s"), and restart ("-r"), just like shutdown.exe. All these operations require elevated permissions if executed remotely. You can provide credentials using the -u (User) and -p (Password) switches.
To put multiple computers into standby mode simultaneously, you can separate their names with commas or write them into a text file, with each computer's name on a separate line. Then, you can call the program as follows:
.\psshutdown64.exe -d -t2 -v "@psshutdown.txt"
In PowerShell, when using the "@" symbol as a prefix, you need to enclose the filename in quotation marks. The "@" symbol is reserved in PowerShell for tasks like creating hash tables or arrays.
Nircmd
In general, the universal command line tool from Nirsoft should also be capable of suspending a computer. This worked flawlessly in my test on the local computer:
nircmd.exe standby
However, attempts to invoke standby mode on a remote PC using the following patterns remained ineffective, and even using the force option didn't change the outcome:
nircmd.exe copy remote \\Remote-PC standby nircmd.exe remote \\Remote-PC standby
Summary
The built-in tools have limited capabilities, allowing a computer only to be shut down, restarted, or put into hibernate mode. The latter is supported only by shutdown.exe, while for the other two options, the cmdlets Stop-Computer and Restart-Computer can be used, and they also work remotely.
Subscribe to 4sysops newsletter!
However, PsShutdown from Sysinternals is recommended as the tool of choice. It offers other interesting features beyond the options described here, which are displayed in the online help (switch -?).
Some thoughts:
rundll32 can be invoked from remote, using the usual suspects:
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
(will hibernate if hibernate is enabled, else, it will let the machine sleep)
Native powershell code:
Add-Type -Assembly System.Windows.Forms
$state = [System.Windows.Forms.PowerState]::Suspend
[System.Windows.Forms.Application]::SetSuspendState($state, $false, $false) | Out-Null
Nice and informative article