Powershell - Displaying and changing the power mode in Windows
To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!
Hello,
For some time now, I’ve been paying more attention to my energy consumption, and of course that includes the power consumption of my work PC. In normal use, I haven’t seen any big difference in power consumption between normal and performance mode (in normal use), but in energy-saving mode I’ve reduced it by more than 60w (roughly 140w instead of 200w).
I haven’t noticed any slowdown in the power consumption of my PC. I didn’t experience any annoying sluggishness in power-saving mode, but to be on the safe side I switch to performance mode when I’m making and encoding videos or 3D.
. But switching from economy to performance takes too much graphical action (and I’m lazy) whereas a small powershell function launches quickly.
# List power modesGet-CimInstance -Name root\cimv2\power -Class Win32_PowerPlan | Select-Object -Property ElementName, instanceid, IsActive# orPowerCfg.exe -list
# List the power mode currently in useGet-CimInstance -Name root\cimv2\power -Class Win32_PowerPlan -filter "IsActive = 'true'"# orPowerCfg.exe -getactivescheme
# Create a custom object$PowerSchemes = Get-CimInstance -Name root\cimv2\power -Class Win32_PowerPlan[System.Collections.ArrayList]$PowerPlan = @()Foreach ( $Scheme in $PowerSchemes ) {$PowerPlan += [pscustomobject]@{Name = $Scheme.elementnameID = $Scheme.InstanceID.Substring(21,36)# Or#ID $Scheme.InstanceID.split('\')[-1].trim('{}')Active = $Scheme.IsActive }}$PowerPlan
# Change the power modeGet-CimInstance -Name root\cimv2\power -Class Win32_PowerPlan | Where-Object ElementName -eq "Power saver" | Invoke-CimMethod -MethodName Activate# or$GUID = 'a1841308-3541-4fab-bc81-f71556f20b4a'Powercfg.exe -SETACTIVE $GUID# 381b4222-f694-41f0-9685-ff5bb260df2e Balanced# 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c High performance# a1841308-3541-4fab-bc81-f71556f20b4a Power saver
This can be turned into two simple functions The first to display the power mode
function Get-PowerPlan {Param ( [switch] $Active, [switch] $List )
# List power modes$PowerSchemes = Get-CimInstance -Name root\cimv2\power -Class Win32_PowerPlan
# Creation of a custom object[System.Collections.ArrayList]$PowerPlan = @()Foreach ( $Scheme in $PowerSchemes ) {$PowerPlan += [pscustomobject]@{Name = $Scheme.elementnameID = $Scheme.InstanceID.Substring(21,36)Active = $Scheme.IsActive}}
# List the power mode currently in useif ( $Active ) {$PowerPlan.Where({$_.active -eq $true}).name }
# Change the power supply modeif ( $List ) {$PowerPlan } }# Display the active power modeGet-PowerPlan -Active
# List the power modesGet-PowerPlan -List
And the second to change the power mode
function Set-PowerPlan {Param ( [GUID] $ID = 'a1841308-3541-4fab-bc81-f71556f20b4a', [string] $Name, [ValidateSet("Balanced", "Performance", "Saver")] $FriendlyName)
# List the power modes$PowerSchemes = Get-CimInstance -Name root\cimv2\power -Class Win32_PowerPlan
# Change the power mode using the IDif ( $Name ) {$null = $PowerSchemes | Where-Object ElementName -eq $Name | Invoke-CimMethod -MethodName Activate }
if ( $ID ) {$null = $PowerSchemes | Where-Object InstanceID -match $ID | Invoke-CimMethod -MethodName Activate }
if ( $FriendlyName ) {switch ($FriendlyName) {"Balanced" { $null = $PowerSchemes | Where-Object InstanceID -match '381b4222-f694-41f0-9685-ff5bb260df2e' | Invoke-CimMethod -MethodName Activate }"performance" { $null = $PowerSchemes | Where-Object InstanceID -match '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' | Invoke-CimMethod -MethodName Activate }"Saver" { $null = $PowerSchemes | Where-Object InstanceID -match 'a1841308-3541-4fab-bc81-f71556f20b4a' | Invoke-CimMethod -MethodName Activate } } } }# Activate a plan via its idSet-PowerPlan -id a1841308-3541-4fab-bc81-f71556f20b4a
# Activate a plan via its nameSet-PowerPlan -Name "High performance"
# Activate the default power-saving modeSet-PowerPlan
# Use a friendlier nameSet-PowerPlan -FriendlyName Saver
Related links
Powershell - Testing network connectivity and port accessibility
Testing network connectivity and port accessibility with PowershellPowershell - Display network connections (equivalent to netstat)
Display network connections (listening ports, active connections...)Powershell - Testing name resolution (equivalent to nslookup)
Powershell commands to test name resolution (equivalent to nslookup)Powershell - View and manage DNS configuration of network interfaces
Powershell commands to display and manage DNS configuration of network interfacesPowershell - Managing IP configuration of network interfaces
Powershell commands to view and modify the IP configuration of network interfacesPowershell - Managing the status and configuration of network interfaces
Powershell commands to view and modify the status and configuration of network interfaces (disable IPv6, enable/disable an interface)
Follow me on
Support me
Last content
Powershell - Testing network connectivity and port accessibility
Powershell - Display network connections (equivalent to netstat)
Powershell - Testing name resolution (equivalent to nslookup)
Powershell - View and manage DNS configuration of network interfaces
Powershell - Managing IP configuration of network interfaces
Powershell - Managing the status and configuration of network interfaces
Powershell and the Left Hand Side
Powershell - Managing disks, partitions and volumes