Start a Conversation

Unsolved

H

3 Posts

7408

December 28th, 2018 03:00

Powershell REST API Script for updating firmware

With OME 3.0 we created a firmware baseline and did a successful firmware update for several M620/630 Blade servers. Cause we are running nearly 200 servers I´m looking for a Powershell Rest API script for starting this update job. Any idea about the syntax error in the script?

Error message:


Invoke-WebRequest : {"error":{"code":"Base.1.0.GeneralError","message":"A general error has occurred. See ExtendedInfo for more information.","@Message.ExtendedInfo":[{"MessageId":"CJOB4035","MessageId":"CJOB4035","RelatedProperties":[],"Message":"Unable to create or update the
job.","MessageArgs":[],"Severity":"Warning","Resolution":"Make sure the request payload is valid and that the current user has sufficient permissions and retry the operation."}]}}

 

 

 

# Variables for Dell EMC OpenManage Enterprise
$user = "admin"
$password = "*******"
$server = "xxxxxxx.com"

 

# | Credentials
$pass = $password
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user, $secpasswd)

# | Ignore 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
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Ssl3, [Net.SecurityProtocolType]::Tls, [Net.SecurityProtocolType]::Tls11, [Net.SecurityProtocolType]::Tls12


# | API Request
$u = "https://$server/api/JobService/Jobs"

 


$JsonBody = '{
"Id": 0,
"JobName": "Blink LED",
"JobDescription": "Blink LED: Turn On",
"Schedule": "startnow",
"State": "Enabled",
"JobType": {
"Id": 3,
"Name": "DeviceAction_Task"
},
"Targets": [
{
"Id": 25064,
"Data": "",
"TargetType": {
"Id": 1000,
"Name": "DEVICE"
}
}
]
}'


$result = Invoke-WebRequest -Uri $u -Credential $credential -Method Post -Body $JsonBody -ContentType 'application/json'

18 Posts

December 28th, 2018 04:00

For me it works if I use basic authentication:

$DellOMEserver = "****"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))

if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore()

$PowerStates = Invoke-RestMethod -Method Get -Uri "https://${DellOMEserver}/api/DeviceService/PowerStates" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} |% value

December 28th, 2018 04:00

I tested the general process for Powershell REST-API request with a Blink-LED Job in the script example below. 

December 28th, 2018 05:00

Thanks for your reply!

I will check and test your suggestion next week at Wednesday and update the discussion afterwards.

18 Posts

January 4th, 2019 02:00

@Anonymous

Is it possible to do Firmware Upgrades via the REST api?

I can't find any examples in the RESt api guide.

18 Posts

January 15th, 2019 06:00

@Anonymous ,

any update on how to do firmware updates via the rest API?

1K Posts

January 16th, 2019 08:00

Hey,

There are a bunch of commands that are required to perform update using REST API. I am collating all of them in a place for you, I shall be posting it up soon.

January 21st, 2019 18:00

Try this:

 

{
  "Id":0,
  "JobName":"Update Firmware",
  "JobDescription":"Update Firmware",
  "Schedule":"startnow", 
  "State":"Enabled",
  "JobType": {
    "Id":5,
    "Name":"Update_Task"
    },
  "Params": [
    {
      "Key": "stagingValue",
      "Value": "false"
    },
    {
      "Key": "signVerify",
      "Value": "true"
    },
    {
      "Key": "complianceUpdate",
      "Value": "true"
    },
    {
      "Key": "operationName",
      "Value": "INSTALL_FIRMWARE"
    },
    {
      "Key": "catalogId",
      "Value": "31"
    },
    {
      "Key": "repositoryId",
      "Value": "21"
    },
    {
      "Key": "complianceReportId",
      "Value": "15"
    }],
  "Targets":[
    {  
      "Id": 102888,      
      "Data": "DCIM:INSTALLED#701__NIC.Slot.1-1-1;DCIM:INSTALLED#741__BIOS.Setup.1-1",      
      "TargetType":      
        {       
          "Id":1000,        
          "Name":"DEVICE"      
        }    
    }]
}

Simply POST this in the body to https:// /api/JobService/Jobs. I have been testing using the RESTED extension to Firefox.

 

Note that you need a few ids/bits of data to make it work:

catalogId
repositoryId
complianceReportId
The Device ID
Component names that you want to update in the "Data" field.

If POST {"Ids":["123456"]} to /api/UpdateService/Actions/UpdateService.GetBaselinesReportByDeviceids then it will return a list of components that need updating and give you the complianceReportId, repositoryId and catalogId

33 Posts

April 24th, 2019 11:00

Did these ever get collected and posted? Would be super helpful!


@DELL-Pupul M wrote:

Hey,

There are a bunch of commands that are required to perform update using REST API. I am collating all of them in a place for you, I shall be posting it up soon.


 

No Events found!

Top