To expand on it a little:
# BLEPower.ps1
# Credit to:
# https://stackoverflow.com/questions/71736070/how-to-get-bluetooth-device-battery-percentage-using-powershell-on-windows
Get-PnpDevice -FriendlyName "*" | Where-Object { $_.InstanceId -match 'BTH' } | ForEach-Object {
$local:test = $_ | Get-PnpDeviceProperty -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2' | Where-Object Type -ne Empty;
if ($test) {
"$($_.FriendlyName): $(Get-PnpDeviceProperty -InstanceId $($test.InstanceId) -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2' | ForEach-Object Data)%"
}
}
NOTE: Apostrophes (') have been turned into
' above.
PS T:\> .\BLEPower.ps1
Basilisk X HyperSpeed: 15%
Air-Fi Touch Hands-Free AG: 100%
MI Portable Bluetooth Speaker Hands-Free AG: 90%
QCY-Q26 Hands-Free AG: 100%
PS T:\>
Note:
- some peripherals don't report battery usage correctly, eg. the
MI Portable Bluetooth Speaker Hands-Free AG above always reports 90%,
- you need to check the device is connected since Windows retains the battery levels even when devices are disconnected, (see here:
StackOverflow).