HP Scripting Tools for Windows PowerShell manual Hostname

Page 15

When a CSV file is imported into PowerShell, it creates an object array that has elements with member name properties set to the first row names, and each element of the array set to each line of the spreadsheet.

CSV input file:

Input1.csv:

Server,Username,Password,HostPower

192.168.1.1,admin,admin123,Yes

192.168.1.3,admin,admin123,Yes

If the input CSV file has Server, Username, Password, and the HostPower values, the following PowerShell script could be used.

PowerShell script:

$path = ".\input1.csv" $csv = Import-Csv $path

$rt = Set-HPiLOHostPower -Server $csv.Server -Username $csv.Username ` -Password $csv.Password -HostPower $csv.HostPower

$rt Format-List

$rt = Get-HPiLOHostPower -Server $csv.Server -Username $csv.Username ` -Password $csv.Password

$rt Format-List

The preceding example imports the CSV file into $csv and then uses the multi-valued parameters to operate on multiple iLOs in a single command. The script then gets the current power setting using the same $csv and lists the results. If both servers were already powered on, the following output would be displayed.

Script output:

IP

: 192.168.1.1

HOSTNAME

: ilohostbc.company.net

STATUS_TYPE

: WARNING

STATUS_MESSAGE

: {Host power is already ON.}

IP

: 192.168.1.3

HOSTNAME

: isabella-vp2.company.net

STATUS_TYPE

: WARNING

STATUS_MESSAGE

: {Host power is already ON.}

IP

: 192.168.1.1

HOSTNAME

: ilohostbc.company.net

STATUS_TYPE

: OK

STATUS_MESSAGE

: OK

HOST_POWER

: ON

IP

: 192.168.1.3

HOSTNAME

: isabella-vp2.company.net

STATUS_TYPE

: OK

STATUS_MESSAGE

: OK

HOST_POWER

: ON

If no errors or warnings were returned from the set cmdlet, only the output from the get cmdlet would be displayed. Set cmdlets return nothing unless there is an error or warning returned from iLO.

Alternatively, just the iLO IP address or host name could be stored in the CSV file, if a single user name, password, and power setting apply to all iLOs.

Using iLO cmdlets on multiple targets 15

Image 15
Contents HP Scripting Tools for Windows PowerShell User Guide Acknowledgments Contents Introduction to HP Scripting Tools for Windows PowerShell Windows PowerShellFeatures Supported operating systems InstallationInstalling HP iLO Cmdlets for Windows PowerShell System prerequisitesClick Start and select Run Uninstalling HP iLO Cmdlets for Windows PowerShellCmdlet Help HP Scripting Tools for Windows PowerShell cmdletsGets the current Enforce AES/3DES Encryption status Obtain more precise and complete asset data Post IPv6 supportUsing the Find-HPiLOcmdlet PowerShell script Piping output from one command to anotherGuid Using iLO cmdlets on multiple targets Using the Update-HPiLOFirmware cmdletHostname Input2.csv Server 192.168.1.1 Log processing examples PowerShell script Return objects and error handling Script writing methodology General issues TroubleshootingSupport and other resources Contacting HPSupport Information Windows PowerShell resources Documentation feedback Index