Release Notes

20 Automating Dell EMC PowerEdge Server Management by using iDRAC REST API with DMTF Redfish and Microsoft PowerShell
# Below code is needed to set up the credentials correctly for PowerShell to
process and accept them.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
$user = $idrac_username
$pass= $idrac_password
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user,
$secpasswd)
# Get current server power state
if ($get_power_state_only -eq "y")
{
# Define the Redfish URI which will be used for GET, PATCH or POST commands.
$u = https://$idrac_ip/redfish/v1/Systems/System.Embedded.1/
# Compile the GET Command
$result = Invoke-WebRequest -Uri $u -Credential $credential -Method Get -
UseBasicParsing
# Conditional statement to check if correct status code was returned by GET
command
if ($result.StatusCode -eq 200)
{
Write-Host
[String]::Format("- PASS, statuscode {0} returned successfully to get current
power state",$result.StatusCode)
}
else
{
[String]::Format("- FAIL, statuscode {0} returned",$result.StatusCode)
return
}
# Parse the output from the GET command with regex to get the current server
power state.
$get_content=$result.Content
$power_state=[regex]::Match($get_content, "PowerState.+?,").Captures[0].value
$power_state=$power_state -replace (",","")
$power_state=$power_state -split (":")
if ($power_state -eq '"On"')
{
Write-Host
Write-Host "- WARNING, Server current power state is ON"
}
else
{
Write-Host
Write-Host "- WARNING, Server current power state is OFF"
}
Write-Host
Write-Host "Supported power control values are:`n`n- On`n- ForceOff`n-
GracefulRestart`n- GracefulShutdown"
return