In some scenarios you need to remove auxiliary power to an HPE ProLiant Server. Specially with more homeoffice it might not be easy to have somebody onsite to pull the power plugs but luckily there is a feature in iLO that you can use. Sadly this is only available via Redfis / REST API but i did a little PowerShell here.
function Reset-HPEServer
{
[CmdletBinding()]
[Alias()]
[OutputType([int])]
Param
(
#iLO URL or IP
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
$ilo,
[parameter(Mandatory=$true)]
$username,
[parameter(Mandatory=$true)]
$password
)
Begin
{
#Approve self signed SSL certificate
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
#ILO common API url
$uri = "https://$ilo/redfish/v1"
}
Process
{
#Login and create webSession and authHeader
$credBody = @{UserName = $username; Password=$password} | ConvertTo-Json
$loginUri = "$uri/Sessions/"
$hpeSession = Invoke-WebRequest -Uri $loginUri -Method Post -Body $credBody -ContentType 'application/json' -SessionVariable webSession
$AuxPowerCycleURI = "$uri/Systems/1/Actions/Oem/Hpe/HpeComputerSystemExt.SystemReset/"
$AuxPowerCylceBody = @{
Action = 'SystemReset'
ResetType = 'AuxCycle'
} | convertto-json
$authHeader = @{"X-Auth-Token" = $hpeSession.Headers.'X-Auth-Token'}
$Return = Invoke-WebRequest -Uri $AuxPowerCycleURI -Method Post -Headers $authHeader -body $AuxPowerCylceBody -WebSession $webSession -ContentType "application/json"
#code message @Message.ExtendedInfo
#---- ------- ---------------------
#iLO.0.10.ExtendedInfo See @Message.ExtendedInfo for more information. {@{MessageId=iLO.2.15.SystemPowerOffRequired}}
if($Return)
{
Write-Host "Got error Message, most probably you have to shutdown the server first"
$return.Content
}
else
{
Write-Host "as iLO resetted you received a timeout error, that is a good sign"
}
}
End
{
#LogOut will no longer work as iLO resetted
#$authHeader = @{'X-Auth-Token' = $session.Headers.'X-Auth-Token'}
#$accountList = Invoke-WebRequest -Uri $hpeSession.Headers.Location -Method Delete -Headers $authHeader -WebSession $webSession
}
}
Hope this is helpful to you.