Solved

Powershell - Update Active PowerPlan

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

705 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

12 Experts available now in Live!

Get 1:1 Help Now