Im trying to identify a way to construct a PS script that could pull out percentage of AC & Battery usage for a given w10 system.
While searching for info and the way to run this, I manage to use some code that looks like follows, but I missing all the rest of it in order t oget exactly what Im looking for:
At this point I manage to find 2 ways to sort this out as follows:
I try using powercfg, great tool, check command bellow:
powercfg /batteryreport /output c:\temp\batteryreport.xml /xml
My porblem with it, its that the output of the xml data is not consumable, lots of codes that only MS knows, HTML nice one, but I can’t find a way to search for the coorect info and inject it as a variable for ex.
Get-WinEvent to get all 105 ID event where plug and unplug AC data is avalible but Im lost in which way or script adoption is needed to get those number:
You can get the event raw xml and filter the properties you need:
Now, at this point the only way I found to find some info itas at option 2, but I dont find a way to put the needed info into a variable so I can then start the calculation part to get porcentages of used type.
$query1 = "select * from Win32_Battery"
$query2 = "Select * from Win32_PortableBattery"
#Create Has tables to get information
$test1 = {}
$test2 = {}
$test1=Get-WmiObject -Query $query1
$test2=Get-WmiObject -Query $query2
#not sure what the differences are between the classes
Just to mention it at least once … Get-WmiObject is deprecated and should no longer be used. And it is not available anymore in PowerShell 6 and above.
Instead use Get-CimInstance.
So your code suggestion would be “translated” to: