Link to home
Start Free TrialLog in
Avatar of ranski
ranski

asked on

Powershell - Update Active PowerPlan

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
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ranski
ranski

ASKER

Ok thanks OBdA.

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

ASKER

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
}