title: Invoke-RestMethod or Invoke-WebRequest version of curl?
body: <p>I'm trying to access a web api for Sonarqube on our local server. The examples in the Sonarqube documentation are all curl-based and I'm trying to translate them to PowerShell, either Invoke-WebRequest or Invoke-RestMethod. I'm having issues with credentials. I keep getting a 401 Not Authorized error. I've reviewed every post I can find on doing this and I don't see a comprehensive complete answer on how to do this. </p>
  
  <p>Here's what I'm running now:</p>
  
  <pre><code>$user='myUserid'
  $password='myPassword'
  $secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
  $cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
  $uri="http://myServer.ad1.prod:9000/api/properties"
  Invoke-RestMethod -Uri $uri -Credential $cred -Method Get
  </code></pre>
  
  <p>And the response is:</p>
  
  <pre><code>Invoke-RestMethod : {"err_code":401,"err_msg":"Unauthorized"}
  </code></pre>
  
  <p>I've run the curl command as defined in the original product documentation and it works. Same userid, same password, same URI, same method. </p>
  
  <p>Can anyone advise?</p>
  
  <p>My curl command is:</p>
  
  <pre><code>curl -u myID:myPassword X GET http://myServer.ad.prod:9000/api/properties
  </code></pre>