/build/static/layout/Breadcrumb_cap_w.png

Invoke-RestMethod is not working

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 http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml

or

curl -O -u admin:Notallowed1! -X GET http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml

I can use without credential also as the readonly access is given to everyone.
curl -o Desktop/uday.xml -X GET http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml

So the Invoke-RestMethod is working.
Invoke-RestMethod -Method GET -Uri "http://192.168.1.10:8081/artifactory/example-repo-local/idmn627build5.exe" -OutFile "c:\users\ukreddy\Desktop\d.exe"

But for deleting or put/upload we require credentials.

Upload:
curl -u admin:Notallowed1! -X PUT http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml -T Desktop/ff.xml
Delete:
curl -u admin:Notallowed1! -X DELETE http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.xml

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 "http://192.168.1.10:8081/artifactory/example-repo-local/idman627build5.exe" -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 "http://192.168.1.10:8081/artif ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + 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 "http://192.168.1.10:8081/artifactory/api/system/version").version - ur00361883 7 years ago

Answers (0)

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