Getting Windows power options under control

Comments 0

Share to social media

I work from a laptop, both at work and at home. In both cases the laptop is either plugged in or I am running on battery power and in both cases I want to make sure that I am using an appropriate Windows power profile. When the laptop is plugged in I want High performance and when it is running on battery I want Power saver . However, Windows thinks it knows best and only offers two profile via the Power options System Tray icon. The options are whatever is current (ie the one i want to swap away from) and Balanced. I never* want to use Balanced – see above. This requires that I click the ‘more power options’ link and then making selections on the following screens.

Time to see if PowerShell can make this a bit easier…

There may be a way to access this information via other means but the first one that I found was the powercfg.exe utility which is readily accessible from PowerShell and if we execute powercfg /? in the command window or in PowerShell we can see all the options available. First of all lets we execute the utility with the -list parameter so we can see the profiles available on the local computer and also the one that is active.


Let’s make a change…


Executing powercfg with the -setactive parameter followed by the GUID of the profile we want to put into effect shows up the next time we execute powercfg -list.

Now it isn’t too difficult to iterate through the list and allow the user the option to select from the available plans, or in my case to write the function so that it will simply switch from High performance to Power save and back with each execution when the function is called with the appropriate parameter. I’ll be adding this to the code that I execute before I start a presentation so that my laptop is running in High performance for all my demos. Here is the function ‘as is’, make sure to understand what it is doing before you run it on a PC that is important to you. I am not responsible for any unwanted affects that this might cause.

I am still learning PowerShell so if you can suggest ways that I can improve this code (I think probably the datatable is a little overkill for a start) then please put your versions and amendments in the comments.

* – OK, one day I might but I never have yet

Load comments

About the author

Jonathan Allen

See Profile

Jonathan Allen has been a SQL Server DBA since 1999, most enjoying performance tuning and development but also working with SSIS, SSRS to provide suitable business solutions. He is SQLSouthWest PASS Chapter Leader, blogs for Simple Talk, is a forum moderator at and is on Twitter. If you would like to find your nearest user group or just want to say hello then he would love to get an email from you.

Jonathan Allen's contributions