Join me tomorrow when I will talk about changing the power plan on servers running Windows Server 2008 R2 and Windows Server 2012.
We have a lot of stuff to do and to see here in Oslo before the user group meeting this evening. Get-CimInstance -Name rootcimv2power -Class win32_PowerPlan -Filter “isactive = true” | If I want to check to see what power plan gets applied as a result of the above script, I can do a simple query to check for the active power plan, as shown here.
Therefore, after a bit of testing, I may eliminate the ElseIf condition, and do a simple If / Else and use the Else condition to set the full power plan. At times, for example, on my laptop, the battery stops charging at 98 percent or so-and I do not know if THAT condition reports as fully charged (3). This is because, with the Windows Battery Conditioning technology, the battery does not always fully charge. What I do not know, yet, is how often the script will select High Performance. Filter “ElementName = ‘High performance'” Invoke-CimMethod -InputObject $p -MethodName Activate }Įlseif ((Get-CimInstance win32_battery).batterystatus -eq 3) $p = Get-CimInstance -Name rootcimv2power -Class win32_PowerPlan ` If ((Get-CimInstance win32_battery).batterystatus -eq 1) The script is a simple If / ElseIF / Else type of construction. I decided, right now, that I will use Power Saver if the battery is discharging (1), High Performance if the battery is fully charged (3) and Balanced, if the battery is any other status. All I really need to do is to add a bit of logic, then retrieve the appropriate power plan, and activate it. To set the power plan on my laptop, I use the Win32_PowerPlan WMI class (see yesterday’s article) and I call the Activate method. (Get-CimInstance win32_battery).batterystatus Set the appropriate power plan However, the battery is not necessarily charging.įor my purpose, I use the value like a Boolean-1 means ”on battery,” everything else means “plugged in” (at least for my script). The system has access to AC so no battery is being discharged. The following chart details the meaning of the status of the battery. ” The other conditions are a bit more complicated. If the laptop runs on the battery, the BatteryStatus reports 1, which means that “The battery is discharging. PS C:> Compare-Object $b.CimClassProperties.name $p.CimClassProperties.nameĮxpectedBatteryLife <= The battery is discharging
PS C:> $p = Get-CimClass win32_portablebattery On the other hand, Win32_Battery provides information about recharge status. This WMI class also derives from Cim_Battery, but it provides a bit more information than Win32_Battery. There is another WMI class-Win32_Portablebattery. In the past, I have had laptops in which the Win32_Battery WMI class did not populate at all when the laptop was plugged into electricity it only became available when the laptop ran on battery. The only thing is to ensure that my laptop actually populates information in the class-and that the information is reliable. There is nothing special about this class. This WMI class is in the RootCimV2 WMI namespace and has been around since forever. To detect whether or not my laptop is running on battery, I can query the Win32_Battery WMI class. Oh well, and the other big difference is a bit of snow! WOO HOO!!! Detect power state by using PowerShell The big difference is the 30-degree temperature between high and low in Charlotte. Interestingly enough, the lows in Oslo and in Charlotte, North Carolina, are about the same. The meeting runs from 18:00 until 20:00 (CET). This evening in Oslo, Norway, the Scripting Wife and I are attending the Microsoft Technology User Group meeting. Microsoft Scripting Guy, Ed Wilson, is here. Summary: Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell to detect the power state on his laptop and to set the appropriate power plan.