Invoke-RESTMethod PowerShell











up vote
-1
down vote

favorite












I am trying to use the Invoke-Restmethod to call a set of API's, but it fails with the below error, i have also posted the same json format, can some let me know what could be wrong ?



    ### Ignore TLS/SSL errors
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]::Tls12


#Create URL string for Invoke-RestMethod
$urlsend = 'https://' + 'vrslcm-01a.corp.local/lcm/api/v1/' + '/login'


#Credential

$Username = "admin@localhost"
$password = "VMware1!"

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
$headers = @{

"description"= "Testing Authentication"
}

$body = @{
$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'
"mode"= $raw
}

Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $body -ContentType 'application/json'


enter image description here



Here is the sample jSON which iam trying to invoke via powershell, it consists of the header and the body. I need to understand how we could call the same jSON POSTMAN example via the PowerShell Invoke-RestMethod



"item": [
{
"name": "authorization",
"description": "",
"item": [
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var response=JSON.parse(responseBody)",
"postman.setEnvironmentVariable("token", response.token)"
]
}
}
],
"request": {
"url": "{{Server}}/lcm/api/v1/login",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{nt"username": "admin@localhost",nt"password": "vmware"n}"
},
"description": ""
},
"response":
},
{
"name": "Logout",
"request": {
"url": "{{Server}}/lcm/api/v1/logout",
"method": "POST",
"header": [
{
"key": "x-xenon-auth-token",
"value": "{{token}}",
"description": ""
}
],
"body": {},
"description": ""
},
"response":
}
]
},









share|improve this question






















  • Could you fix it? Was any of the answers helpful?
    – wp78de
    2 days ago















up vote
-1
down vote

favorite












I am trying to use the Invoke-Restmethod to call a set of API's, but it fails with the below error, i have also posted the same json format, can some let me know what could be wrong ?



    ### Ignore TLS/SSL errors
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]::Tls12


#Create URL string for Invoke-RestMethod
$urlsend = 'https://' + 'vrslcm-01a.corp.local/lcm/api/v1/' + '/login'


#Credential

$Username = "admin@localhost"
$password = "VMware1!"

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
$headers = @{

"description"= "Testing Authentication"
}

$body = @{
$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'
"mode"= $raw
}

Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $body -ContentType 'application/json'


enter image description here



Here is the sample jSON which iam trying to invoke via powershell, it consists of the header and the body. I need to understand how we could call the same jSON POSTMAN example via the PowerShell Invoke-RestMethod



"item": [
{
"name": "authorization",
"description": "",
"item": [
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var response=JSON.parse(responseBody)",
"postman.setEnvironmentVariable("token", response.token)"
]
}
}
],
"request": {
"url": "{{Server}}/lcm/api/v1/login",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{nt"username": "admin@localhost",nt"password": "vmware"n}"
},
"description": ""
},
"response":
},
{
"name": "Logout",
"request": {
"url": "{{Server}}/lcm/api/v1/logout",
"method": "POST",
"header": [
{
"key": "x-xenon-auth-token",
"value": "{{token}}",
"description": ""
}
],
"body": {},
"description": ""
},
"response":
}
]
},









share|improve this question






















  • Could you fix it? Was any of the answers helpful?
    – wp78de
    2 days ago













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am trying to use the Invoke-Restmethod to call a set of API's, but it fails with the below error, i have also posted the same json format, can some let me know what could be wrong ?



    ### Ignore TLS/SSL errors
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]::Tls12


#Create URL string for Invoke-RestMethod
$urlsend = 'https://' + 'vrslcm-01a.corp.local/lcm/api/v1/' + '/login'


#Credential

$Username = "admin@localhost"
$password = "VMware1!"

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
$headers = @{

"description"= "Testing Authentication"
}

$body = @{
$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'
"mode"= $raw
}

Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $body -ContentType 'application/json'


enter image description here



Here is the sample jSON which iam trying to invoke via powershell, it consists of the header and the body. I need to understand how we could call the same jSON POSTMAN example via the PowerShell Invoke-RestMethod



"item": [
{
"name": "authorization",
"description": "",
"item": [
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var response=JSON.parse(responseBody)",
"postman.setEnvironmentVariable("token", response.token)"
]
}
}
],
"request": {
"url": "{{Server}}/lcm/api/v1/login",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{nt"username": "admin@localhost",nt"password": "vmware"n}"
},
"description": ""
},
"response":
},
{
"name": "Logout",
"request": {
"url": "{{Server}}/lcm/api/v1/logout",
"method": "POST",
"header": [
{
"key": "x-xenon-auth-token",
"value": "{{token}}",
"description": ""
}
],
"body": {},
"description": ""
},
"response":
}
]
},









share|improve this question













I am trying to use the Invoke-Restmethod to call a set of API's, but it fails with the below error, i have also posted the same json format, can some let me know what could be wrong ?



    ### Ignore TLS/SSL errors
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]::Tls12


#Create URL string for Invoke-RestMethod
$urlsend = 'https://' + 'vrslcm-01a.corp.local/lcm/api/v1/' + '/login'


#Credential

$Username = "admin@localhost"
$password = "VMware1!"

$basicAuth = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($Username):$Password"))
$headers = @{

"description"= "Testing Authentication"
}

$body = @{
$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'
"mode"= $raw
}

Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $body -ContentType 'application/json'


enter image description here



Here is the sample jSON which iam trying to invoke via powershell, it consists of the header and the body. I need to understand how we could call the same jSON POSTMAN example via the PowerShell Invoke-RestMethod



"item": [
{
"name": "authorization",
"description": "",
"item": [
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var response=JSON.parse(responseBody)",
"postman.setEnvironmentVariable("token", response.token)"
]
}
}
],
"request": {
"url": "{{Server}}/lcm/api/v1/login",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": "{nt"username": "admin@localhost",nt"password": "vmware"n}"
},
"description": ""
},
"response":
},
{
"name": "Logout",
"request": {
"url": "{{Server}}/lcm/api/v1/logout",
"method": "POST",
"header": [
{
"key": "x-xenon-auth-token",
"value": "{{token}}",
"description": ""
}
],
"body": {},
"description": ""
},
"response":
}
]
},






powershell






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 6:11









PowerShell

81332447




81332447












  • Could you fix it? Was any of the answers helpful?
    – wp78de
    2 days ago


















  • Could you fix it? Was any of the answers helpful?
    – wp78de
    2 days ago
















Could you fix it? Was any of the answers helpful?
– wp78de
2 days ago




Could you fix it? Was any of the answers helpful?
– wp78de
2 days ago












2 Answers
2






active

oldest

votes

















up vote
0
down vote













Like the error states, the problem is your hash definition.




A null key is not allowed in a hash literal.




PowerShell tries to evaluate $raw as a hash table key. Since it hasn't been defined before it is null and fails because null is not allowed. Try it like this:



$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'

$body = @{
"mode"= $raw
}





share|improve this answer





















  • I tried this, but got the below error Invoke-RestMethod : {"message":"Unparseable JSON body: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","statusCode":400,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1
    – PowerShell
    Nov 7 at 6:44




















up vote
0
down vote













make $raw to a hashtable like



$raw = @{
username=$Username
password=$Password
}


add this hashtable to the $body hashtable



$body = @{         
mode= $raw
}


but now it still is a hashtable the api cannot use. thus convert it to json like



$jsonBody = $body | ConvertTo-Json


using $jsonBody should then work when used like



Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $jsonBody -ContentType 'application/json'





share|improve this answer





















  • I tried this - but get the below error - Invoke-RestMethod : {"message":"forbidden","statusCode":500,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1 + Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    – PowerShell
    Nov 7 at 8:35










  • so the post was successful but the authentication did fail. please read the docs how to authenticate docs.vmware.com/en/vRealize-Suite/2017/… also .. did you check if powershellgallery.com/packages/VMware.PowerCLI has cmdlets for what you are trying?
    – Guenther Schmitz
    Nov 7 at 9:10













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184364%2finvoke-restmethod-powershell%23new-answer', 'question_page');
}
);

Post as a guest
































2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Like the error states, the problem is your hash definition.




A null key is not allowed in a hash literal.




PowerShell tries to evaluate $raw as a hash table key. Since it hasn't been defined before it is null and fails because null is not allowed. Try it like this:



$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'

$body = @{
"mode"= $raw
}





share|improve this answer





















  • I tried this, but got the below error Invoke-RestMethod : {"message":"Unparseable JSON body: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","statusCode":400,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1
    – PowerShell
    Nov 7 at 6:44

















up vote
0
down vote













Like the error states, the problem is your hash definition.




A null key is not allowed in a hash literal.




PowerShell tries to evaluate $raw as a hash table key. Since it hasn't been defined before it is null and fails because null is not allowed. Try it like this:



$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'

$body = @{
"mode"= $raw
}





share|improve this answer





















  • I tried this, but got the below error Invoke-RestMethod : {"message":"Unparseable JSON body: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","statusCode":400,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1
    – PowerShell
    Nov 7 at 6:44















up vote
0
down vote










up vote
0
down vote









Like the error states, the problem is your hash definition.




A null key is not allowed in a hash literal.




PowerShell tries to evaluate $raw as a hash table key. Since it hasn't been defined before it is null and fails because null is not allowed. Try it like this:



$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'

$body = @{
"mode"= $raw
}





share|improve this answer












Like the error states, the problem is your hash definition.




A null key is not allowed in a hash literal.




PowerShell tries to evaluate $raw as a hash table key. Since it hasn't been defined before it is null and fails because null is not allowed. Try it like this:



$raw= '{nt"username": "admin@localhost",nt"password": "vmware"n}'

$body = @{
"mode"= $raw
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 6:38









wp78de

9,43151636




9,43151636












  • I tried this, but got the below error Invoke-RestMethod : {"message":"Unparseable JSON body: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","statusCode":400,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1
    – PowerShell
    Nov 7 at 6:44




















  • I tried this, but got the below error Invoke-RestMethod : {"message":"Unparseable JSON body: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","statusCode":400,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1
    – PowerShell
    Nov 7 at 6:44


















I tried this, but got the below error Invoke-RestMethod : {"message":"Unparseable JSON body: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","statusCode":400,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1
– PowerShell
Nov 7 at 6:44






I tried this, but got the below error Invoke-RestMethod : {"message":"Unparseable JSON body: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $","statusCode":400,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1
– PowerShell
Nov 7 at 6:44














up vote
0
down vote













make $raw to a hashtable like



$raw = @{
username=$Username
password=$Password
}


add this hashtable to the $body hashtable



$body = @{         
mode= $raw
}


but now it still is a hashtable the api cannot use. thus convert it to json like



$jsonBody = $body | ConvertTo-Json


using $jsonBody should then work when used like



Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $jsonBody -ContentType 'application/json'





share|improve this answer





















  • I tried this - but get the below error - Invoke-RestMethod : {"message":"forbidden","statusCode":500,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1 + Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    – PowerShell
    Nov 7 at 8:35










  • so the post was successful but the authentication did fail. please read the docs how to authenticate docs.vmware.com/en/vRealize-Suite/2017/… also .. did you check if powershellgallery.com/packages/VMware.PowerCLI has cmdlets for what you are trying?
    – Guenther Schmitz
    Nov 7 at 9:10

















up vote
0
down vote













make $raw to a hashtable like



$raw = @{
username=$Username
password=$Password
}


add this hashtable to the $body hashtable



$body = @{         
mode= $raw
}


but now it still is a hashtable the api cannot use. thus convert it to json like



$jsonBody = $body | ConvertTo-Json


using $jsonBody should then work when used like



Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $jsonBody -ContentType 'application/json'





share|improve this answer





















  • I tried this - but get the below error - Invoke-RestMethod : {"message":"forbidden","statusCode":500,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1 + Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    – PowerShell
    Nov 7 at 8:35










  • so the post was successful but the authentication did fail. please read the docs how to authenticate docs.vmware.com/en/vRealize-Suite/2017/… also .. did you check if powershellgallery.com/packages/VMware.PowerCLI has cmdlets for what you are trying?
    – Guenther Schmitz
    Nov 7 at 9:10















up vote
0
down vote










up vote
0
down vote









make $raw to a hashtable like



$raw = @{
username=$Username
password=$Password
}


add this hashtable to the $body hashtable



$body = @{         
mode= $raw
}


but now it still is a hashtable the api cannot use. thus convert it to json like



$jsonBody = $body | ConvertTo-Json


using $jsonBody should then work when used like



Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $jsonBody -ContentType 'application/json'





share|improve this answer












make $raw to a hashtable like



$raw = @{
username=$Username
password=$Password
}


add this hashtable to the $body hashtable



$body = @{         
mode= $raw
}


but now it still is a hashtable the api cannot use. thus convert it to json like



$jsonBody = $body | ConvertTo-Json


using $jsonBody should then work when used like



Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body $jsonBody -ContentType 'application/json'






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 7 at 6:58









Guenther Schmitz

7111214




7111214












  • I tried this - but get the below error - Invoke-RestMethod : {"message":"forbidden","statusCode":500,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1 + Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    – PowerShell
    Nov 7 at 8:35










  • so the post was successful but the authentication did fail. please read the docs how to authenticate docs.vmware.com/en/vRealize-Suite/2017/… also .. did you check if powershellgallery.com/packages/VMware.PowerCLI has cmdlets for what you are trying?
    – Guenther Schmitz
    Nov 7 at 9:10




















  • I tried this - but get the below error - Invoke-RestMethod : {"message":"forbidden","statusCode":500,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1 + Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    – PowerShell
    Nov 7 at 8:35










  • so the post was successful but the authentication did fail. please read the docs how to authenticate docs.vmware.com/en/vRealize-Suite/2017/… also .. did you check if powershellgallery.com/packages/VMware.PowerCLI has cmdlets for what you are trying?
    – Guenther Schmitz
    Nov 7 at 9:10


















I tried this - but get the below error - Invoke-RestMethod : {"message":"forbidden","statusCode":500,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1 + Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
– PowerShell
Nov 7 at 8:35




I tried this - but get the below error - Invoke-RestMethod : {"message":"forbidden","statusCode":500,"documentKind":"com:vmware:xenon:common:ServiceErrorResponse","errorCode":0} At line:1 char:1 + Invoke-RestMethod -Method POST -uri $urlsend -Headers $headers -Body ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
– PowerShell
Nov 7 at 8:35












so the post was successful but the authentication did fail. please read the docs how to authenticate docs.vmware.com/en/vRealize-Suite/2017/… also .. did you check if powershellgallery.com/packages/VMware.PowerCLI has cmdlets for what you are trying?
– Guenther Schmitz
Nov 7 at 9:10






so the post was successful but the authentication did fail. please read the docs how to authenticate docs.vmware.com/en/vRealize-Suite/2017/… also .. did you check if powershellgallery.com/packages/VMware.PowerCLI has cmdlets for what you are trying?
– Guenther Schmitz
Nov 7 at 9:10




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184364%2finvoke-restmethod-powershell%23new-answer', 'question_page');
}
);

Post as a guest




















































































Popular posts from this blog

横浜市

Rostock

Europa