@@ -228,23 +228,26 @@ function Set-Newline {
228
228
function Get-BatteryInfo {
229
229
if ($env: OS -eq ' Windows_NT' -or $IsWindows ) {
230
230
231
- if (! (Get-CimInstance win32_battery)) { return }
231
+ $batteryclass = Get-CimInstance win32_battery
232
+ if (! $batteryclass ) { return }
232
233
233
- $charge = (Get-CimInstance win32_battery).EstimatedChargeRemaining
234
- $connected = (Get-CimInstance - Class batterystatus - Namespace root\wmi).PowerOnline
235
- $charging = (Get-CimInstance - Class batterystatus - Namespace root\wmi).Charging
234
+ $powerclass = Get-CimInstance - Class batterystatus - Namespace root\wmi
235
+ $charge = $batteryclass.EstimatedChargeRemaining
236
+ $connected = $powerclass.PowerOnline
237
+ $charging = $powerclass.Charging
236
238
237
239
} elseif ($IsLinux ) {
238
240
239
241
$syspath = " /sys/class/power_supply/"
240
- if (! (Get-ChildItem $syspath )) { return }
242
+ $syspathcontents = Get-ChildItem $syspath
243
+ if (! $syspathcontents ) { return }
241
244
242
- $powerclass = (Get-ChildItem $syspath | Where-Object { $_.Name -like ' AC*' }).Name
245
+ $powerclass = ($syspathcontents | Where-Object { $_.Name -like ' AC*' }).Name
243
246
if ($powerclass -is [Object []]) { $powerdevice = $syspath + $powerclass [-1 ] }
244
247
else { $powerdevice = $syspath + $powerclass }
245
248
$connected = Get-Content " $powerdevice /online"
246
249
247
- $batteryclass = (Get-ChildItem $syspath | Where-Object { $_.Name -like ' BAT*' }).Name
250
+ $batteryclass = ($syspathcontents | Where-Object { $_.Name -like ' BAT*' }).Name
248
251
if ($batteryclass -is [Object []]) { $batterydevice = $syspath + $batteryclass [-1 ] }
249
252
else { $batterydevice = $syspath + $batteryclass }
250
253
$charge = Get-Content " $batterydevice /capacity"
0 commit comments