HOWTO: Using Powershell Sleep Command on Remote Computer

If you want to bring the device from Windows 10 to sleep without waiting period of time, you can use the powershell sleep command.

To begin with, it is worth explaining that sleep mode is a low-power state in which the system suspends processes and activity and turns off the display in order to save energy as much as possible. This is a kind of alternative to shutting down, but with the ability to quickly wake up a computer and continue working at the point where you left off.

In fact, there are several types of sleep mode:

  • Sleep mode - the system and its processes are paused, the screen goes out and Windows goes into sleep. When you turn off or jump electricity - all active processes and open files will be lost.

  • Hibernation - processes and open applications are saved to the hyberfil.sys file, the screen goes blank and the device goes into hibernation, in which, if there is a power jump or a sudden shutdown, all files will be saved when you turn it on again. Hibernation is used mainly for laptops, therefore, when the battery is completely discharged, Windows goes into hibernation and restores work from the same place when charging is connected (if the corresponding item is enabled in the settings).

But there are also questions - hybrid sleep mode in Windows 10, what is it? In fact, this is hibernation, but only for stationary computers. It combines saving all active applications to a file, as in hibernation and fast waking up, as in sleep mode. In Windows 10, this term is not used and is referred to as hibernation, both on stationary PCs and laptops.

Under the concept of sleep mode in Windows 10, we will perceive all 3 types (sleep, hibernation and hybrid), since they have common settings and work according to a general principle.

Well, there was not one. Most of the PowerShell cmdlets are dealing with automation of servers and odd ball functions like sleeping a laptop normally would not be a top priority of the Windows Management Foundation / PowerShell group. Enough said... So, this guide show you how to sleep remote computers with help of PowerShell.

1. First Step Is to Open Elevated PowerShell Prompt

  • To open an elevated PowerShell prompt, in the taskbar search, type powershell.

  • Now see the result Windows PowerShell which appears on the top. Right-click on it and select Run as Administrator.

    Step 1 to use powershell sleep command is to Run PowerShell as Administrator


  • Then you will see a confirmation prompt from UAC. Click Yes, and PowerShell will open.

    Step 2 to use powershell sleep command is to click yes on UAC prompt


  • An elevated PowerShell prompt will display Administrator: Windows PowerShell on the top in the prompt’s border.

    elevated PowerShell prompt


  • NOTES:

  • You can also open Task Manager > File menu > Run new task. Type powershell and select the Create this task with administrative privileges check box and click OK to open an elevated PowerShell prompt.

    Run new task Powershell


  • Press Shift+Ctrl+Alt and then click on the PowerShell icon to open PowerShell as administrator.

Next Step to use powershell sleep command is to open elevated PowerShell prompt

The next step will describe how to use powershell sleep command or rather the script.

2. Use This Script to Sleep Remote Computer

  • Set-StrictMode –Version latest
  • Function Sleep-Computer {
  • #
  • .SYNOPSIS
  • Place your computer into Sleep mode
  • .DESCRIPTION
  • Since there is not a cmdlet that will 'sleep' your computer, the Sleep-Computer function was born. You can use
  • the force option to override/clear your hibernate setting and then sleep if you need to...
  • .EXAMPLE
  • c:\PS>Sleep-Computer -WhatIf
  • What if: Performing operation "Sleep-Computer" on Target Computer.
  • .EXAMPLE
  • c:\PS>Sleep-Computer -Confirm -Force
  • Confirm
  • Are you sure you want to perform this action?
  • Performing operation "Sleep-Computer" on Target "V-RONEES-W8MBP".
  • [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
  • #>
  • [cmdletbinding(SupportsShouldProcess=$True,ConfirmImpact="Low")]
  • param (
  • [parameter(mandatory=$false)][switch]$Force
  • )
  • if ($pscmdlet.ShouldProcess($env:COMPUTERNAME)) {
  • if ($Force.IsPresent) {
  • if ($pscmdlet.ShouldProcess("Turning off hibernation")) {
  • & powercfg -hibernate off
  • }
  • }
  • $rundll = Join-Path -Path ($env:windir) -ChildPath "System32\rundll32.exe"
  • & ($rundll) powrprof.dll,SetSuspendState 0,1,0
  • }
  • }

    Also consider using Action1 to sleep remote computer if:

    • - You need to perform this action on multiple (hundreds or even thousands) computers simultaneously.
    • - Some of your endpoints are laptops not connected to corporate network at all times.

    Action1 is a cloud-based platform for software deployment, software/hardware inventory, patch management, endpoint configuration and more. It is free with basic functionality.


    Other Relevant HOWTOs: