Scripting Question

Invoke-RestMethod is not working

06/25/2017 4157 views
With the CURL.exe I am able o download,put and delete a file.

--For downloading the file.--
curl -o Desktop/uday.xml -u admin:Notallowed1! -X GET


curl -O -u admin:Notallowed1! -X GET

I can use without credential also as the readonly access is given to everyone.
curl -o Desktop/uday.xml -X GET

So the Invoke-RestMethod is working.
Invoke-RestMethod -Method GET -Uri "" -OutFile "c:\users\ukreddy\Desktop\d.exe"

But for deleting or put/upload we require credentials.

curl -u admin:Notallowed1! -X PUT -T Desktop/ff.xml
curl -u admin:Notallowed1! -X DELETE

So, when I try to pass credential object, the powershell commandlet is not working..
$r = get-credential
In the I am passing the crendentials to $r variable when the credentials prompt appeared..

Invoke-RestMethod -Method DELETE -Uri "" -credential $r

But I am getting below error.
Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
At line:1 char:1
+ Invoke-RestMethod -Method DELETE -Uri " ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Can anyone suggest how to do this...

1 Comment   [ + ] Show comment


  • even i am getting the version details also but without credentials
    (Invoke-RestMethod -Method GET -Uri "").version

Be the first to answer this question

This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ