UNSOLVED

Hendrik2018

updated

8 years ago

0

7670

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'