Public/Invoke-IdracPowerAction.ps1

Function Invoke-IdracPowerAction{
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [string]$iDRACName,

        [Parameter(Mandatory = $true)]
        [ValidateSet("PowerUp","GracefullShutdown","PowerDown","HardReset","PowerCycle")]
        [string]$Action,

        [System.Management.Automation.PSCredential]$Credential
    )

    begin{
        $actionKeyword = $null
        Switch ($Action){
            "PowerUp" {$actionKeyword = "powerup"}
            "GracefullShutdown" {$actionKeyword = "graceshutdown"}
            "PowerDown" {$actionKeyword = "powerdown"}
            "HardReset" {$actionKeyword = "hardreset"}
            "PowerCycle" {$actionKeyword = "powercycle"}
        }

        $session = New-iDRACSession -iDRACName $iDRACName -Credential $Credential
    }

    process{

        $result = Invoke-SshCommand -Command "racadm serveraction $actionKeyword" -SSHSession $session
        $msg = $result.Host.ToUpper() + " - " + $result.Output
        Write-Verbose -Message $msg
    }

    End{
        $session | Remove-SSHSession | Out-Null
    }
}