Important Notice: On February 29th, this community will be put into read-only mode. All existing posts will remain but customers will be unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Answered

Feature Request: Power Status

I 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.

0

Comments

2 comments
Date Votes
  • 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.

    0
  • $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"

    0

Please sign in to leave a comment.

Didn't find what you were looking for?

New post