Showing posts with label remote. Show all posts
Showing posts with label remote. Show all posts

Thursday, December 19, 2019

Working with iDRAC9 Redfish API using PowerShell - Part 4


In this article, I will explain how to use iDRAC Redfish API to Power On and Graceful Shutdown a server using PowerShell. This is applicable to all Dell EMC servers having iDRAC. It can be a general-purpose PowerEdge rack server, Ready Node, Appliance, etc. I've tested on iDRAC9.

Note: In a production environment please make sure to follow proper shutdown or reboot procedure (if any) before performing any system reset actions on the server.

[CmdletBinding()]
param(
    [Parameter(Mandatory)]
    [String]$idrac_ip,

    [Parameter(Mandatory)]
    [ValidateSet('On''GracefulShutdown')]
    [String]$ResetType
)

#To fix the connection issues to iDRAC REST API
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
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11

#Get iDRAC creds
$Credentials = Get-Credential -Message "Enter iDRAC Creds"

$JsonBody = @{"ResetType" = $ResetType} | ConvertTo-Json
$u1 = "https://$($idrac_ip)/redfish/v1/Systems/System.Embedded.1/Actions/ComputerSystem.Reset"

Invoke-RestMethod -Uri $u1 -Credential $Credentials -Method Post -UseBasicParsing -ContentType 'application/json' -Body $JsonBody -Headers @{"Accept"="application/json"} -Verbose


Hope it was useful. Cheers!

Related posts



References


iDRAC9 Redfish API guide

Wednesday, March 15, 2017

Running a PowerShell script on multiple remote machines simultaneously

Below example shows how to trigger PowerShell scripts on a remote Windows machine and run as background jobs.

trigger.ps1

Invoke-Command -ComputerName testvm-03 -ScriptBlock {&C:\posh\io\iostress.ps1} -AsJob
Invoke-Command -ComputerName testvm-02 -ScriptBlock {&C:\posh\io\iostress.ps1} -AsJob
Invoke-Command -ComputerName testvm-01 -ScriptBlock {&C:\posh\io\iostress.ps1} -AsJob

Invoke-Command is used to execute scripts remotely. Above script (trigger.ps1) invokes a PS script (iostress.ps1) on 3 remote machines. Here the script being executed is saved on the corresponding remote machine itself. As each of the invoke-command is running as a background job on the local machine, the second invoke-command doesn't have to wait for the first invoke-command to complete and the third invoke-command doesn't have to wait for the first and second invoke-commands to complete. From the user perspective the command prompt returns immediately even if the jobs take longer time to complete. This case will be useful if you want to run a script on multiple remote machines at the same time.