function onBattery { if ((Get-WmiObject -Class Win32_Battery | Select-Object -ExpandProperty batterystatus) -eq 2) { write-output "Plugged In" } else { write-output "On Battery" } }