Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Powershell Dell iDrac redfish Rest API basic authentication

In one of my blog Configure Dell iDrac9 Rest API with Powershell I showed how use x-auth-token to connect to Dell iDrac, here I instead of token, using basic authentication (use UserName and Password each time to connect to Redfish iDRAC rest api), This is just a example and I will be using explicit credential in Invoke-RestMethod.

Microsoft Powershell dell idrac basic authentication rest api automation script ps1 invoke-restmethod certificatepolicy trustallcertspolicy new-object x509cert system.embeeded redfish.png

As you can see each time it need to create a session using credential and get the information. 

For more information check the document.
https://topics-cdn.dell.com/pdf/idrac9-lifecycle-controller-v3303030_api-guide_en-us.pdf
https://topics-cdn.dell.com/pdf/idrac9-lifecycle-controller-v4x-series_api-guide_en-us.pdf
https://www.dell.com/support/manuals/in/en/inbsd1/idrac9-lifecycle-controller-v4.x-series/idrac9_4.00.00.00_redfishapiguide_pub/manageraccount?guid=guid-a54042ff-86b7-4904-94b0-927e19894800&lang=en-us
https://downloads.dell.com/manuals/all-products/esuprt_software/esuprt_it_ops_datcentr_mgmt/dell-management-solution-resources_white-papers11_en-us.pdf

Dell ilo idrac redfish SSL ceritificate rest api login metadata systemroot selfsigend certificate @odata integrated dell remote access controller basic authentication.png

Download this script here, or it is also available on github.com/kunaludapi.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#iDRAC9 IP and credentials
$iDRAC9 = '192.168.34.224'
$credentials =  Get-Credential -Message "Type iDRAC9 credentials" -UserName root

try
{
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 [Sytstem.Net.SecurityProtocolType]::Tls11
    Write-Host 'Allowed SelfSigned SSL certificate for this iDRAC session'
}
catch
{
    Write-Host 'Already Allowed SelfSigned SSL certificate for this iDRAC session'
}

#curl example
#curl "https://<iDRAC IP>/redfish/v1/Chassis" -k -u root:calvin

#Example API URI to get iDRAC9 Information
$basicAPIUrl = 'https://$iDRAC9/redfish/v1'
$systemAPIUrl = 'https://$iDRAC9/redfish/v1/Systems/System.Embedded.1'

#Common Header Example
$Headers = @{'Accept'='application/json'}

#Results
$basicInfo = Invoke-RestMethod -Uri $basicAPIUrl -Credential $credentials -Method Get -ContentType 'application/json' -Headers $Headers #-UseBasicParsing
$basicInfo

$systemInfo = Invoke-RestMethod -Uri $basicAPIUrl -Credential $credentials -Method Get -ContentType 'application/json' -Headers $Headers #-UseBasicParsing
$systemInfo.MemorySummary

Useful Articles
PowerShell Convert MAC address to Link-local address IPv6
PowerShell Invoke-WebRequest The request was aborted Could not create SSL TLS secure channel
PowerShell Invoke-WebRequest The underlying connection was closed: Could not establish trust relationship for the SSL TLS secure channel.
Powershell Write-Eventlog The source name test does not exist on computer localhost
Powershell New-Object Retrieving the COM class factory for component with CLSID 80040154 Class not registered (Exception from HRESULT 0x80040154 (REGDB_E_CLASSNOTREG))

Go Back

Comment

Blog Search

Page Views

12085154

Follow me on Blogarama