Using the script mentioned in an earlier answer, I've rewrote it to improve it's usability. Save it as a powershell module (.psm1) to the system profile folder ($PsHome\Profile.ps1).
Then create a schedule task to run at the time you want to place the computer to sleep. In the actions tab set to the parameters you want.
Example:
Powershell -ExecutionPolicy Bypass -NoLogo -NonInteractive -Command "& {nap -PowerState Hibernate}"
function Suspend_Computer {
<#
.Synopsis
Sets the computer to a specified power mode.
.Description
The computer will be placed either in sleep or hibernation modes.
.Example
C:\PS>Suspend_Computer
Description
-----------
The command will run using default parameters which are not force the action of Suspend.
.Example
C:\PS>Suspend_Computer -Force $True -PowerState Hibernate
Description
-----------
The computer will save all data to disk and hibernate.
.Link
https://superuser.com/questions/505247/how-to-script-the-windows-7-sleep-command
#>
Param(
[Parameter(Mandatory =$False,Position=0)]
$Force = $False,
[Parameter(Mandatory=$False,Position=1)]
$DisableWake = $False,
[Parameter(Mandatory=$False,Position=2)]
[ValidateSet("Suspend","Hibernate")]
[string]$PowerState = 'Suspend'
)
Add-Type -AssemblyName System.Windows.Forms
$PowerState = [System.Windows.Forms.PowerState]::$PowerState;
[System.Windows.Forms.Application]::SetSuspendState($PowerState, $Force, $DisableWake);
}
new-alias -name nap -value Suspend_Computer
/h hibernates the machine, it doesn't sleep it. – Enigma – 2013-02-04T16:58:26.707
@Enigma: You're correct. I've updated my answer. – martineau – 2013-02-04T21:08:46.663
As stated in the question, I've been unable to get this to work via the Task Scheduler – benwh – 2013-03-16T18:19:56.867
benwh: Yes, I can read. An important point I was trying to make my answer was that in order to get it to work with the Task Scheduler, may require enabling it in a one or two places. – martineau – 2013-03-16T19:36:58.927
If it wasn't configured correctly elsewhere in the system, why would Hybrid Sleep work correctly when initiating it via Start -> Sleep, or using that command via the run prompt? – benwh – 2013-03-16T21:27:21.780
benwh: The first link is to a discussion where
rundll32command does not put the system into hybrid sleep, even though hybrid sleep is enabled and can be entered into manually via the Start menu -- because of a mismatch with the ACPI settings in the BIOS, I believe. – martineau – 2013-03-17T00:52:20.373You haven't mentioned whether you using a desktop or laptop, but apparently hybrid sleep is off by default on laptops and you may need to turn it on.
– martineau – 2013-03-17T01:45:26.347