Detecting whether a device is running on AC power or battery is a common requirement in enterprise scripting — from Intune Remediations that skip power-hungry tasks on battery-only devices, to SCCM compliance baselines checking laptop power state before triggering updates. This updated guide replaces the deprecated Get-WmiObject approach with the modern Get-CimInstance equivalent, and expands the original single-liner into practical, production-ready scripts.
| Detail | |
|---|---|
| Last Updated | March 2026 |
| Applies To | Windows 10, Windows 11 |
| WMI Classes Used | Win32_Battery, BatteryStatus (root\wmi), BatteryFullChargedCapacity |
| Difficulty | Beginner |
Get-WmiObject vs Get-CimInstance
The original article used Get-WmiObject, which has been deprecated since PowerShell 3.0 and removed entirely in PowerShell 7+. All examples in this guide use Get-CimInstance, which is the modern replacement, works identically for all WMI queries, and is compatible with PowerShell 5.1 through 7.x.
| Old (deprecated) | Modern equivalent |
|---|---|
| Get-WmiObject -Class Win32_Battery | Get-CimInstance -ClassName Win32_Battery |
| Get-WmiObject -Class BatteryStatus -Namespace root\wmi | Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus |

Check if Device is on AC Power
The quickest one-liner — returns True if plugged in, False if on battery:
(Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus).PowerOnline
For devices with multiple batteries (some enterprise laptops have two), the property returns an array. Use this to handle both single and multi-battery devices safely:
$batteryStatus = Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus
$isOnAC = $batteryStatus | Where-Object { $_.PowerOnline -eq $true }
if ($isOnAC) {
Write-Host "Device is connected to AC power."
} else {
Write-Host "Device is running on battery."
}
Reusable Function: Test-IsOnACPower
A clean, reusable function suitable for including in larger scripts or Intune Remediations:
function Test-IsOnACPower {
<#
.SYNOPSIS
Returns $true if the device is connected to AC power, $false if on battery.
Returns $null if no battery is detected (e.g. desktop PC).
#>
try {
$batteries = Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus -ErrorAction Stop
if (-not $batteries) { return $null } # No battery — desktop
return [bool]($batteries | Where-Object { $_.PowerOnline -eq $true })
} catch {
Write-Warning "Could not query battery status: $_"
return $null
}
}
# Usage
$acStatus = Test-IsOnACPower
switch ($acStatus) {
$true { Write-Host "On AC power" }
$false { Write-Host "On battery" }
$null { Write-Host "No battery detected (desktop or VM)" }
}
Get Full Battery Information
For a complete picture — charge percentage, estimated runtime, charging state, and power source — combine both WMI classes:
$battery = Get-CimInstance -ClassName Win32_Battery
$batStatus = Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus
# BatteryStatus numeric values reference
$statusMap = @{
1 = "Discharging"
2 = "On AC Power"
3 = "Fully Charged"
4 = "Low"
5 = "Critical"
6 = "Charging"
7 = "Charging and High"
8 = "Charging and Low"
9 = "Charging and Critical"
11 = "Partially Charged"
}
[PSCustomObject]@{
DeviceName = $env:COMPUTERNAME
PowerOnline = $batStatus.PowerOnline
Charging = $batStatus.Charging
Discharging = $batStatus.Discharging
ChargePercent = "$($battery.EstimatedChargeRemaining)%"
EstimatedRunTime = "$($battery.EstimatedRunTime) min"
BatteryStatusText = $statusMap[[int]$battery.BatteryStatus]
Voltage = "$([math]::Round($batStatus.Voltage / 1000, 2)) V"
}
Check Battery Health (Wear Level)
Beyond just power state, you can calculate battery wear — how much capacity has been lost compared to the original design capacity. This is useful for fleet health monitoring via Intune Remediations or SCCM compliance baselines:
$designCapacity = (Get-CimInstance -Namespace root\wmi -ClassName BatteryStaticData).DesignedCapacity
$fullChargeCapacity = (Get-CimInstance -Namespace root\wmi -ClassName BatteryFullChargedCapacity).FullChargedCapacity
if ($designCapacity -and $fullChargeCapacity) {
$healthPercent = [math]::Round(($fullChargeCapacity / $designCapacity) * 100, 1)
Write-Host "Battery health: $healthPercent% of original capacity remaining"
if ($healthPercent -lt 50) {
Write-Host "WARNING: Battery health is critically low — consider replacement"
} elseif ($healthPercent -lt 80) {
Write-Host "NOTICE: Battery health is degraded"
} else {
Write-Host "Battery health is good"
}
} else {
Write-Host "Could not retrieve capacity data — virtual machine or unsupported hardware"
}
Practical Use Case: Intune Remediation — Skip Task if on Battery
A common pattern in Intune Remediations is to skip resource-intensive tasks (disk cleanup, compliance scans, large software installs) when the device is unplugged. Here is a detection script template that reports non-compliant only when on AC power — ensuring the remediation only runs when plugged in:
# Detection script: only trigger remediation if device is on AC power
# Exit 0 = compliant (skip remediation)
# Exit 1 = non-compliant (run remediation)
try {
$batteries = Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus -ErrorAction Stop
# No battery = desktop, always run
if (-not $batteries) {
Write-Host "No battery detected — proceeding"
exit 1
}
$onAC = [bool]($batteries | Where-Object { $_.PowerOnline -eq $true })
if ($onAC) {
Write-Host "On AC power — proceeding with remediation"
exit 1 # Trigger remediation
} else {
Write-Host "On battery — skipping remediation"
exit 0 # Skip remediation
}
} catch {
Write-Host "Error querying battery: $_"
exit 0 # Fail safe — skip if unsure
}
Bulk Fleet Query via Invoke-Command
To query battery and power status across multiple remote devices simultaneously (requires WinRM / PSRemoting enabled):
$computers = @("PC001", "PC002", "PC003")
$results = Invoke-Command -ComputerName $computers -ScriptBlock {
$bat = Get-CimInstance -ClassName Win32_Battery
$status = Get-CimInstance -Namespace root\wmi -ClassName BatteryStatus
if (-not $bat) {
return [PSCustomObject]@{ Computer = $env:COMPUTERNAME; Status = "No battery" }
}
[PSCustomObject]@{
Computer = $env:COMPUTERNAME
PowerOnline = $status.PowerOnline
ChargePercent = $bat.EstimatedChargeRemaining
Charging = $status.Charging
}
}
$results | Format-Table -AutoSize
Generate a Battery Report (Built-in Windows Tool)
For a detailed HTML battery health report — including charge history, capacity history, and battery life estimates — Windows has a built-in tool that requires no scripting:
# Generate battery report and open it in the default browser
powercfg /batteryreport /output "$env:USERPROFILE\Desktop\battery-report.html"
Start-Process "$env:USERPROFILE\Desktop\battery-report.html"
The report includes capacity history going back 30 days, usage patterns, and a comparison of designed vs full charge capacity — effectively the same data as the battery health script above, presented in a graphical format. Useful for documenting battery degradation when justifying hardware replacement to management.
BatteryStatus Values Reference
| Value | Meaning |
|---|---|
| 1 | Discharging — on battery, not plugged in |
| 2 | On AC Power — plugged in, not charging (full) |
| 3 | Fully Charged |
| 4 | Low battery |
| 5 | Critical battery |
| 6 | Charging |
| 7 | Charging and High |
| 8 | Charging and Low |
| 9 | Charging and Critical |
| 11 | Partially Charged |
Summary
Querying battery and AC power status via PowerShell covers a surprisingly wide range of real enterprise scenarios — from Intune Remediation guards to fleet-wide battery health monitoring. Use Get-CimInstance instead of the deprecated Get-WmiObject, and combine both WMI classes (Win32_Battery and root\wmi\BatteryStatus) for complete power state information.
- Use
Get-CimInstance -Namespace root\wmi -ClassName BatteryStatusforPowerOnline,Charging, andDischargingproperties - Use
Get-CimInstance -ClassName Win32_Batteryfor charge percentage, estimated runtime, and BatteryStatus numeric value - Use
BatteryStaticDataandBatteryFullChargedCapacityfor wear level / health percentage - Always handle the
$nullcase — desktops and VMs return no battery object and will throw errors if not guarded - Use
powercfg /batteryreportfor a visual 30-day battery history report
