Feature Request: Power Status
AnsweredI could really use the ability to determine if a computer is on AC power or battery. This way I could avoid pushing certain updates to machines that are on battery.
-
I've seen some articles on WMI queries for battery. They may be, technically, "unsupported" queries. Take a look at https://devblogs.microsoft.com/scripting/using-windows-powershell-to-determine-if-a-laptop-is-on-battery-power/
Very interesting. You can use WMI to get the BatteryStatus=1 (but some laptops may discharge even when plugged in). The article recommends using PowerOnline instead, but it's unsupported. See how those work. Hopefully that gets you in the right direction.
-
$Is_Laptop_Plugged = (Get-WmiObject -Class BatteryStatus -Namespace root\wmi).PowerOnline if ($Is_Laptop_Plugged -eq $true) { Write-Output "The laptop is plugged in" } else { Write-Error "The laptop is on battery" }
Just use the code above as the first step of your deployment and set the Error Mode (under Options) to "Stope Deployment with Error"
Please sign in to leave a comment.
Comments
2 comments