Solved

Powershell - Update Active PowerPlan

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

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

Utilizing an array to gracefully append to a list of EmailAddresses
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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