简体   繁体   English

查询多个电池Powershell脚本get-wmiobject win32_battery

[英]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.

相关问题 PowerShell Get-WmiObject WIN32_VOLUME WHERE子句 - PowerShell Get-WmiObject WIN32_VOLUME WHERE clause 将Get-WmiObject win32_diskdrive转换为Powershell 4中的阵列 - Convert Get-WmiObject win32_diskdrive to array in Powershell 4 PowerShell:向Get-WmiObject添加过滤器或查询 - PowerShell: Adding filter or query to Get-WmiObject Powershell get-netadapter与frrom get-wmiobject win32_networkadapter不同 - Powershell get-netadapter differs frrom get-wmiobject win32_networkadapter Get-WMIObject无法枚举增强的Powershell中的Win32_LogicalDiskToPartiion - Get-WMIObject fails to enumerate Win32_LogicalDiskToPartiion in elevated powershell 为什么Powershell中的Get-WMIObject Win32_Process这么慢,有哪些替代方案? - Why is Get-WMIObject Win32_Process in Powershell so slow and what are the alternatives? powershell的Get-WmiObject -Win32_Share类返回空路径 - powershell's Get-WmiObject -Class Win32_Share returns null paths powershell (Get-WmiObject win32_physicalmedia).serialnumber 输出十六进制 - powershell (Get-WmiObject win32_physicalmedia).serialnumber output hex Powershell:从get-wmiobject win32_product过滤不需要的值 - Powershell: Filtering unwanted values from get-wmiobject win32_product get-wmiobject使用Win32_NTLogEvent拉日志 - get-wmiobject to pull logs using Win32_NTLogEvent
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM