[英]query multiple batteries powershell script get-wmiobject win32_battery
So I am attempting to use a script I found to monitor four UPSs and send shutdown signals to around 15 servers. 因此,我尝试使用我发现的脚本来监视四个UPS,并将关闭信号发送到大约15台服务器。 I am pretty new to PowerShell, and would love some assistance in being able to query multiple UPS units. 我对PowerShell很陌生,希望在查询多个UPS单元方面获得一些帮助。
Here is the script: (It's long, I thought a pastebin would be easier): http://pastebin.com/Uya5Nkwv 这是脚本:(很长一段时间,我认为pastebin会更容易): http : //pastebin.com/Uya5Nkwv
I've tried the following, but to no avail. 我尝试了以下方法,但无济于事。
PS C:\Users\myuser> get-wmiobject win32_battery | select "JS0745012650American P
ower ConversionSmart-UPS 2200 RM FW:665.6.D USB FW:7.3"
JS0745012650American Power ConversionSmart-UPS 2200 RM FW:665.6.D USB FW:7.3
----------------------------------------------------------------------------
PS C:\Users\myuser> get-wmiobject win32_battery | select EstimatedRunTime where
DeviceID like JS07*
Select-Object : A positional parameter cannot be found that accepts argument 'w
here'.
At line:1 char:37
+ get-wmiobject win32_battery | select <<<< EstimatedRunTime where DeviceID li
ke JS07*
+ CategoryInfo : InvalidArgument: (:) [Select-Object], ParameterB
indingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.SelectObjectCommand
PS C:\Users\myuser>
Basically there are five UPs and when I do 基本上有五个UP,当我这样做时
get-wmiobject win32_battery
I am able to view a unique identifier: 我能够查看唯一标识符:
DeviceID : JS0748005250American Power ConversionSmart-UPS 30
00 RM FW:666.6.D USB FW:7.3
So how can I query all of the UPSs in said script? 那么如何查询上述脚本中的所有 UPS? Once I figure out how to do that, I'm pretty sure I can figure out the shutdown signal/csv file. 一旦确定了操作方法,就可以确定关闭信号/ csv文件了。
You do not need to manually iterate through the batteries, and you are already 99% there, really. 您无需手动遍历电池,实际上,您已经有99%的电池了。
Get-WmiObject win32_battery | Where-Object {$_.DeviceID -match "JS07"} | select estimatedruntime
That should do exactly what you want, assuming all DeviceIDs contain JS07 as part of their identifier. 假设所有DeviceID都包含JS07作为其标识符的一部分,那么这应该可以完全满足您的要求。
If you want more information, like the device ID or Name: 如果您需要更多信息,例如设备ID或名称:
Get-WmiObject win32_battery | Where-Object {$_.DeviceID -match "JS07"} | select Name, estimatedruntime
Modify that script to iterate through a list of computer names. 修改该脚本以遍历计算机名称列表。 Starting at line 94 insert a foreach statement eg foreach ($computer in 'pc1','pc2','pc3','pc4') {
and put a closing }
at the end of the script. 从第94行开始,插入一个foreach语句,例如foreach ($computer in 'pc1','pc2','pc3','pc4') {
并在脚本末尾添加一个结束foreach ($computer in 'pc1','pc2','pc3','pc4') {
}
。 This will cycle the script through each computer you provide. 这将在您提供的每台计算机上循环脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.