Sometimes, you might want to send a computer into power-saving mode remotely or from the command line. The onboard utilities offer limited options for this, and PowerShell offers none at all. As alternatives, two free utilities from Microsoft's Sysinternals and NirSoft get the job done.

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.

Listing all PsShutdown options

Listing all PsShutdown options

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.

Put the remote computer into sleep mode with PsShutdown

Put the remote computer into sleep mode with PsShutdown

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.

Read the names of remote computers from a text file

Read the names of remote computers from a text file

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 -?).

avataravataravatar
2 Comments
  1. Welf Alberts (Rank 3) 2 months ago

    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

  2. Stellispro 1 month ago

    Nice and informative article

Leave a reply

Your email address will not be published. Required fields are marked *

*

© 4sysops 2006 - 2023

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account