HP Scripting Tools for Windows PowerShell User Manual

Page 16

Advertising
background image

CSV input file:

Input2.csv:
Server
192.168.1.1
192.168.1.3

If the input CSV file has only iLO IP or hostname and there is a common username and password
for logging in, and if all the servers have to be switched on, the following script could be used.

PowerShell script:

$path = ".\input2.csv"
$csv = Import-Csv $path
$rt = Set-HPiLOHostPower -Server $csv.Server -Username "admin" `
-Password "admin123" -HostPower "Yes"
$rt | Format-List
$rt = Get-HPiLOHostPower -Server $csv.Server -Username "admin" `
-Password "admin123"
$rt | Format-List

The preceding example imports into $csv and then uses the multiple server array to power on all
servers included in the CSV file. The same username, password, and power setting are used for
both iLOs. The output is the same as the previous command.

A similar command to power off could also be entered at the PowerShell prompt as follows:

PS C:\Users\yourname> Set-HPiLOHostPower -Server @(“192.168.1.1”,” 192.168.1.3”)
-Username “admin” -Password “admin123” -HostPower No

If different usernames and passwords are used, then the following command could be used:

PS C:\Users\yourname> Set-HPiLOHostPower -Server @(“192.168.1.1”,” 192.168.1.3”)
-Username @(“admin1”,”admin2”) -Password @(“password111”,”password222”) -HostPower No

You could also use the imported server list and have the cmdlet prompt for the needed parameters
as in the following script.

PowerShell script:

$path = ".\input2.csv"
$csv = Import-Csv $path
$rt = Set-HPiLOHostPower -Server $csv.Server
$rt | Format-List
$rt = Get-HPiLOHostPower -Server $csv.Server -Username "admin" -Password "admin123"
$rt | Format-List

Script output:

Username not provided...
Use same username for all servers (y/n) : y
Please enter Username: admin
Password not provided...
Use same Password for all servers (y/n) : y
Please enter password: ********
Hostpower not provided...
Use same Hostpower for all servers (y/n) : y
Please enter Hostpower: Yes

IP : 192.168.1.1
HOSTNAME : ilohostbc.company.net
STATUS_TYPE : WARNING
STATUS_MESSAGE : {Host power is already ON.}

16

HP Scripting Tools for Windows PowerShell cmdlets

Advertising