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   [ - ] Hide Comment


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

There are no answers at this time
Answer this question or Comment on this question for clarity