
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.
#2009 teredac mac mini power supply windows
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.
