Put your PC into Standby or Hibernate with Powershell

by dstock 4. May 2009 16:00

When ever I leave my desk, I make sure that I lock my workstation for security reasons.  That's fine for security but it doesn't do much for saving power as my computer just sits there idle.   I wrote a quick PowerShell function that puts the computer into Standby.  When I come back it only takes a couple seconds to start back up and I am saving some power.  I added the line below to my $profile

 

$ret = ni -p function: -value {[Reflection.Assembly]::LoadwithPartialname("System.Windows.Forms")>$null;$ret=[System.Windows.Forms.Application]::SetSuspendState(0,0,0);} -name gsb

 

 (gsb is short for Go To Standby)

 Now when I leave my desk for a few minutes I just type in gsb in Powershell and voila, power saving. Remember that this puts all your processes on hold and your computer will be off the network.

For this script to work, your pc must support ACPI enabled.  If you want to put the computer into hibernate instead of standby, change the first 0 to a 1  aka SetSupendState(1,0,0)

In the future I hope to publish a PowerShell Cmdlet  Set-PowerState.  This will allow you via script to set your PC into either Hibernate or Standby (as above).  In addition on supported systems, it will cause them to wake up at a set time.   I have another project I need to finish first but hopefully I'll have a first version out soon.

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

PowerShell

Comments

Comments are closed

Powered by BlogEngine.NET 1.4.5.0
Theme by Extensive SEO

About the blog

Focusing on PeopleSoft, SQL, PowerShell, C# and anything else that tweaks my interest