Solved

Powershell - Update Active PowerPlan

Posted on 2016-11-01
3
35 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 83

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
A brief introduction to what I consider to be the best editor for PowerShell.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short film showing how OnPage and Connectwise integration works.

948 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now