Trying to execute an APIC-EM REST (GET) call via a PowerShell script.
The APIC-EM is self-certified hence need to use the first bulk of code lines ..
[System.Net.ServicePointManager]::CheckCertificateRevocationList = $false;
Add-Type @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
"@
[ServerCertificateValidationCallback]::Ignore();
[System.Net.ServicePointManager]::CheckCertificateRevocationList = $false;
;
$Splat = @{
Method = 'GET'
Uri = 'https://10.122.6.150/api/v1/discovery/1'
ContentType = "application/json"
Headers = @{authorization = "X-Auth-Token:ST-3166-nHrsi63Rbvkwze5aznoN-cas" }
}
$response = Invoke-RestMethod @Splat
After running the script (in PS admin window), getting the following error:
Invoke-RestMethod : { "response":{"errorCode":"RBAC","message":"Failed to provide a CAS service ticket to validate","detail":"Failed to provide a CAS service ticket to validate"}, "version":"1.0"} At C:\psScripts\rest2.ps1:38 char:13
+ $response = Invoke-RestMethod @Splat
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
The Token is working when running a query from through Postman (see screenshot)
the header is called "x-auth-token", not "authorisation". Did you try:
Headers = @{X-Auth-Token = "ST-3166-nHrsi63Rbvkwze5aznoN-cas" }
changed that to the following and it worked well (command: https://10.122.6.150/api/v1/discovery/count)
changed the “Write-Host $response” to “Write-output $response” and I do see additional lines,
Refer the code here -https://github.com/darrenstarr/APICEMPowershell
it should be able to automate the entire process of claiming new devices, filling in template variables and deploying them.. Added a far more advanced templating system .
Comments
0 comments
Please sign in to leave a comment.