Solved

Powershell - Update Active PowerPlan

Posted on 2016-11-01
3
50 Views
Last Modified: 2016-11-02
Hi all,

I've put together a tiny powershell script to check the active power scheme and then change the value for when i close the lid to do nothing on laptops.

##### Variables  # # #  # # # 
# Lets Check what is our Current Active "Power Scheme" and put it on a Variable 
 
$currScheme = POWERCFG -GETACTIVESCHEME  
 
Powercfg.exe /setdcvalueindex $currScheme 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 0

Open in new window


Unfortunately I keep getting the below error

Powercfg.exe : Invalid Parameters -- try "/?" for help

Any ideas?

thanks
0
Comment
Question by:ranski
  • 2
3 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41870115
Two issues:
* The schemeGUID argument requires the GUID only, while "powercfg.exe /GetActiveScheme" returns something like "Power Scheme GUID: <GUID> (Balanced)".
* In Powershell, enclose arguments that contain spaces or hyphens in quotes.
If ((& powercfg.exe /GetActiveScheme) -match '(?<GUID>[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12})') {
	$currScheme = $Matches['GUID']
	"Current scheme is '$($currScheme)'" | Write-Host
	# & powercfg.exe /SetDCValueIndex $currScheme '4f971e89-eebd-4455-a8de-9e59040e7347' '5ca83367-6e45-459f-a27b-476b1d01c936' 0
} Else {
	"Could not query the active scheme!" | Write-Error
}

Open in new window

0
 

Author Comment

by:ranski
ID: 41870358
Ok thanks OBdA.

I tried your code above and it doesn't return an error but also doesn't change the power scheme setting.
0
 

Author Comment

by:ranski
ID: 41870365
Found the issue. Noticed the line was # out

If ((& powercfg.exe /GetActiveScheme) -match '(?<GUID>[a-f0-9]{8}-(?:[a-f0-9]{4}-){3}[a-f0-9]{12})') {
      $currScheme = $Matches['GUID']
      "Current scheme is '$($currScheme)'" | Write-Host
      # & powercfg.exe /SetDCValueIndex $currScheme '4f971e89-eebd-4455-a8de-9e59040e7347' '5ca83367-6e45-459f-a27b-476b1d01c936' 0
} Else {
      "Could not query the active scheme!" | Write-Error
}
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question