Quantcast
Channel: FreeBeing » PowerShell
Viewing all articles
Browse latest Browse all 10

Bateria restante – Powershell

$
0
0

Às vezes, quando reinicio o note, some da barra de tarefas o ícone com a carga da bateria. Já tentei dizer pro vista que é pra ele sempre ser mostrado, mas nem sempre esse SO obedece a gente. Sendo assim, busquei uma forma de conseguir essa informação de outro jeito, e como estou mexendo um bocadinho em PowerShell, aqui vai a dica.

O segredo é usar WMI (Windows Management Interface). Segue o código:

$info = get-WmiObject win32_battery -computer  
"Remaing Battery: "+ $info.EstimatedChargeRemaining

Agora, pra ficar mais fácil, crie um arquivo de nome Get-BatteryLevel.ps1, ponha as linhas abaixo e salve:

$info = get-WmiObject win32_battery -computer $Args[0] 
"Remaing Battery: "+ $info.EstimatedChargeRemaining

Com isso é possível saber o nível da bateria chamando no PowerShell:

& Get-BatteryLevel.ps1 <nome_do_computador>

o que já é ligeiramente mais simples.



Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles