Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
HP ilo powershell interface
#enter ilo IP address here
$ilourl = "https://192.168.1.14"
$jsonpage = $ilourl + "/json/login_session"
#disable certificate check
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
#first, login and get session cookie in $ws
$postParams = @{
'method' = "login"
'user_login' = "administrator"
'password' = "ilopassword"
}
$postParams = $postParams | ConvertTo-Json
$var = Invoke-RestMethod -Method Post -Uri $jsonpage -Body $postParams -sessionvariable ws
$session = $var.session_key
#get current power state
$powerpage = $ilourl + "/json/host_power"
$var = Invoke-RestMethod -Method get -Uri $powerpage -WebSession $ws
#soft press the button (clean shutdown or boot or whatever)
$postParams = @{
'method' = "press_power_button"
'session_key' = $session
}
$postParams = $postParams | ConvertTo-Json
$custHeaders = @{ "X-Auth-Token"= $session };
$var = Invoke-RestMethod -Method post -Uri $powerpage -Body $postParams -WebSession $ws -Headers $custHeaders
#overview
#session_info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment