Feature Request: Power Status

Answered

Comments

2 comments

  • Avi Solomon

    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
    Comment actions Permalink
  • Wei
    $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
    Comment actions Permalink

Please sign in to leave a comment.