Skip to content

Instantly share code, notes, and snippets.

@mendel129
Created September 21, 2015 18:19
Show Gist options
  • Save mendel129/7ed5012bd1d25c1e4558 to your computer and use it in GitHub Desktop.
Save mendel129/7ed5012bd1d25c1e4558 to your computer and use it in GitHub Desktop.
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