Test-Battery

Topics: Archive - General
Apr 27, 2014 at 10:37 AM
Edited Apr 27, 2014 at 11:30 AM
Hello,

Excuse me for my bad english
On function Test-Battery,if your laptop can have multiple batteries, the test does not work if only one battery is present and on the sector. If you use the code below, it works:
write-host "Testing power connection status..."

$onPower = $false

$batteryStatus = Get-WmiObject -Class BatteryStatus -Namespace root\wmi -ComputerName . -ErrorAction SilentlyContinue
If ($batteryStatus) {
    $batteryStatus|foreach {
        $power = $_.PowerOnLine
        If ($power) {
            write-host "AC Power connection found."
            $onPower = $true
        }
    }

    if ($onPower) 
        {Return $false}
}

write-host "AC Power connection not found"
Return $true
}

Bye
Eric
Coordinator
Apr 29, 2014 at 1:00 PM
Hi Eric,

Nice catch thanks! I'll include this change in the next release.

Dan