Skip to content

Instantly share code, notes, and snippets.

@cbilson
Created February 10, 2016 17:14
Show Gist options
  • Save cbilson/3925863ab6201b80b5ef to your computer and use it in GitHub Desktop.
Save cbilson/3925863ab6201b80b5ef to your computer and use it in GitHub Desktop.
function Sleep-Computer {
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="Low")]
param([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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment