質問

So I am attempting to use a script I found to monitor four UPSs and send shutdown signals to around 15 servers. I am pretty new to PowerShell, and would love some assistance in being able to query multiple UPS units.

Here is the script: (It's long, I thought a pastebin would be easier): 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

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? Once I figure out how to do that, I'm pretty sure I can figure out the shutdown signal/csv file.

役に立ちましたか?

解決

You do not need to manually iterate through the batteries, and you are already 99% there, really.

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.

If you want more information, like the device ID or Name:

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 e.g. foreach ($computer in 'pc1','pc2','pc3','pc4') { and put a closing } at the end of the script. This will cycle the script through each computer you provide.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top