Getting Windows power options under control

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.

PowerOptions01.png

Let’s make a change…

PowerOptions02.png

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