beautypg.com

Piping output from one command to another – HP Scripting Tools for Windows PowerShell User Manual

Page 14

background image

StatusMessage : OK
Firmware : 3.11
ProductName : c3000 Tray with embedded DDR2 Onboard Administrator

IP : 192.168.242.63
Hostname : westwind.company.net
StatusType : OK
StatusMessage : OK
Firmware : 4.11
ProductName : BladeSystem c7000 DDR2 Onboard Administrator with KVM

IP : 192.168.242.64
Hostname : southwind.company.net
StatusType : OK
StatusMessage : OK
Firmware : 4.11
ProductName : c3000 Tray with embedded DDR2 Onboard Administrator

The above example script assigns the objects returned to a variable and then prints it out. There
are two additional parameters in this script also. To monitor the operation of the Find-HPOA
cmdlet, we use the Verbose parameter. The verbose output tells you that 6 threads are being
used for the operation and then it pings each address to test for systems in the range. You then
see verbose output that lists unsuccessful attempts at finding an OA. The last output is the printing
of the object $OAS, that contains the three OAs found.

The Timeout parameter default is 300 milliseconds. If the timeout value is not long enough for
OAs to respond, try using a Timeout parameter with a larger value. A value of 1000 milliseconds
should provide reliable operation over even the longest distance.

In the preceding two commands no double quotes are required around the Range parameter, but
if a comma is included in the range, double quotes are required. This is because the use of a
comma is interpreted as a list separator by PowerShell. Without double quotes, part of what should
be a string is interpreted by PowerShell as a number. The operation of combined ranges is defined
as creating a combination of each subnet address with each other subnet.

The following are examples of input range parameters using double quotes.

Description

Range Parameter

Specifies two addresses to check, 192.168.1.1 and 192.168.1.15.

“192.168.1.1,15”

Specifies four addresses to check, 192.168.217.93, 192.168.217.103,
192.168.216.93, 192.168.216.103.

“192.168.217,216.93,103”

Specifies twenty-two addresses to check, 192.168.217.93 through
192.168.217.103 and 192.168.216.93 through 192.168.216.103.

“192.168.217,216.93-103”

Piping output from one command to another

A useful feature of PowerShell is the ability to pipe output from one command to another. The
preceding section provided examples of using Find-HPOA to locate OA devices. You may want
to use those with other commands rather than input the OAs you find again or store them somewhere
and re-use them.

The following is a script that pipes output from Find-HPOA through Add-Member to add two
required fields, then to Connect-HPOA, and then to Get-HPOAPower to produce the power
information for the OAs found. The –Verbose parameter is used to view more information.

PowerShell script:

$EncInfo = Find-HPOA 192.168.242.60-65 -Verbose |
% {Add-Member -PassThru -InputObject $_ Username Administrator}|
% {Add-Member -PassThru -InputObject $_ Password Admin}|
Connect-HPOA |

14

HP Scripting Tools for Windows PowerShell cmdlets