如何在 Windows 上使用 PowerShell 获取蓝牙设备电池百分比?
我正在尝试绘制蓝牙耳机电池放电图表。为此,我需要读取所连接设备的电池百分比。我可以在设备的 GUI 上看到电源信息。有没有办法使用 PowerShell 获取连接的蓝牙设备的电池百分比信息? (比如使用 wmi 或其他任何东西)
I am trying to plot a graph for Bluetooth headphone battery discharge. For that I need to read battery percentage of the connected device. I can see power information is available on GUI for the device. Is there any way to get the battery percentage info for connected Bluetooth device using PowerShell? (like using wmi or anything else)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
根据我的发现,您可以使用 Get-PnpDevice cmdlet 获取有关蓝牙设备的信息。这应该返回 PnP 设备及其状态、类、FriendlyName 和 InstanceID 的列表。
您可以使用 -Class 参数过滤结果。要指定蓝牙 PnP 设备,您可以输入“Bluetooth”作为 -Class 参数的字符串值。
然后,您可以使用 -FriendlyName 参数通过其FriendlyName 从此列表中指定您想要的设备,并输入所需设备的FriendlyName 作为参数的字符串值。
注意:您还可以使用 -InstanceId 参数指定设备,并将设备的 InstanceId 作为参数的字符串值提供。
如果随后将上一个命令通过管道传递给 Get-PnpDeviceProperty cmdlet,它将返回设备属性的列表,包括其 InstanceId、KeyName、Type 和 Data。
除此之外,我还可以通过使用 -KeyName 参数并输入(我假设)包含设备电源数据的属性的 KeyName 作为参数的字符串值来进一步过滤命令的结果。
不幸的是,这就是我所能解决的问题。希望我的贡献有所帮助。
In my findings, you can get information on Bluetooth devices using the Get-PnpDevice cmdlet. This should return a list of PnP Devices, their Status, Class, FriendlyName and InstanceID.
You can filter the results with -Class parameter. To specify Bluetooth PnP devices, you can enter "Bluetooth" as a string value for the -Class parameter.
You can then specify the device you have in mind from this list by their FriendlyName using the -FriendlyName parameter and enter the desired device's FriendlyName as a string value for the parameter.
Note: You can also specify the device using the -InstanceId parameter and providing the device's InstanceId as a string value for the parameter.
If you then pipe the previous command to the Get-PnpDeviceProperty cmdlet, it will return a list of the device's properties, including its InstanceId, KeyName, Type and Data.
Beyond this point, I was able to further filter the results of the command by using the -KeyName parameter and entering the KeyName of the property that (I assume) contains Device Power Data as a string value for the parameter.
Unfortunately this is as far as I've gotten to solving the problem. Hopefully my contribution helps.
保罗·阿马拉尔(Paulo Amaral)的评论确实是答案。
下面的代码将为您提供一个命令,您可以重用以查询设备的电池状态:
对于我的
< headSET>
设备,输出看起来与:Paulo Amaral's comment above is indeed the answer.
The code below will provide you with a command you can reuse to query the battery state of your device:
For my
<Headset>
device, the output looked similar to:据我所知,由于Windows设置中看到的电池状态 - &gt;蓝牙设备来自供应商/设备驱动程序,截至目前,PowerShell似乎无法接近,除非我不知道有一些异国情调的Snapin。
您可以通过此命令获取所有可能的设备信息:
或者,如果您不确定设备的命名是如何命名的,则将返回“设备”的完整列表:
此外,我在注册表中找不到电池信息 - 也许有人可以扩展更多知识,因为注册表可能包含必要的信息,因为必须将其存储在设备上的某个地方。
As far as I am aware, there is no way to poll bluetooth device data beyond what you would get with Get-WmiObject, since the battery status seen in Windows Settings -> Bluetooth Devices is something coming from the vendors/devices driver and seems to, as of now, be inaccessible by PowerShell, unless there is some exotic snapin I am not aware of.
You can get all possible device information via this command:
Or if you are unsure how the device is named as of now, this would return a complete list of "devices":
Additionally, I couldn't find battery information in the registry - maybe someone more knowledge can expand on that because the registry probably contains the necessary information as it must be stored somewhere on the device.
看来这个解决方案对来这里的人很少有效。
它没有给我想要的结果。我正在使用 Jabra 的耳机。
我在不同的电池电量下收集了这整组数据。
对我来说不幸的是,我没有得到一个值反映电池百分比的KeyName。
我没有看到列表中的任何其他值根据 GUI 中显示的电池百分比发生变化。
我的 KeyName 集如下:
Microsoft 本身正在读取该数据,这就是他们在通知中显示数据的方式。
微软准备好为这些重要信息推出更容易的阅读机制了吗?
It seems the solution worked for few who came looking here.
It is NOT giving me the desired results. I am using Jabra's headset.
I gathered this whole set of data at its different battery level.
Unfortunately for me, I am NOT getting a KeyName who's value reflects battery percentage.
I do NOT see any other value from the list that changed as per battery percentage shown in GUI.
My set of KeyName is as follwing:
Microsoft is itself reading that data, that's how they display it in notification.
Is Microsoft ready to roll out easier reading mechanism for such crucial information?
我被蓝牙赶上了班级。事实证明,我的蓝牙耳机将电池信息存储在系统类中的设备中。我找到了一种过滤以基本上像Lockzsmith一样过滤找到合适的设备的方法。就像对于Jabra设备一样,您可以这样做:
I got caught up on the Class being Bluetooth. It turns out my bluetooth headset stored the battery info in a device in the System Class. I found a way to filter to find the right device basically like Lockzsmith. Like for a jabra device you might do this:
要检查连接到计算机的所有蓝牙设备的电池百分比,只需运行以下命令:
to check the battery percentage of all Bluetooth devices connected to the computer, simply run the following command: