Here is my Code Snip
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$body = "{`"kind`":`"vm`", `"filter`":`"vm_name==.*VMName*`"}"
$username = "Admin";
$password = ConvertTo-SecureString –String "AdminPassword" –AsPlainText -Force
$credential = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $username, $password
$base64AuthInfo = hConvert]::ToBase64String(4Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
$response = Invoke-RestMethod 'https://PRISMIP:9440/api/nutanix/v3/vms/list' -Method 'POST' -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Body $body -Credential $credential
$response | ConvertTo-Json
And my Response is
Invoke-RestMethod : {"state": "ERROR", "code": 401, "message_list": e{"reason": "AUTHENTICATION_REQUIRED", "message": "Authentication required.", "details": "Basic realm=\"Intent Gateway Login Required\""}], "api_version": "3.1"}
At C:\Scripts\Untitled1.ps1:9 char:13
+ $response = Invoke-RestMethod 'https://PRISMIP:9440/api/nutanix/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) RInvoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Ive tried several different methods of authenticating.
Where am I going wrong here?