title: Powershell Invoke-WebRequest doesnt work with token
body: <p>Im trying to execute ansible tower jobtemplate API to check if the given template ID is valid. However, I am always getting unauthorized status code. Im generating token from ansible tower and sending it to next webreqeust. Below is the code snapshot of what I am trying to do, any clue what I am missing here. Does powershell support token based authentication or is there a different way to set a token in webrequest ?</p>
  <p>Any help is much appreciated.</p>
  <pre><code>try {
      $json=ConvertTo-Json (@{&quot;username&quot;=&quot;*****&quot;;&quot;password&quot;=&quot;******&quot;;})
      $token = (Invoke-WebRequest -Uri &quot;https://www.ansiblet.com/api/v1/authtoken/&quot;  -Body $json -ContentType &quot;application/json&quot; -Method POST).content | ConvertFrom-Json
  
  $headers = @{Authorization=&quot;Bearer $token&quot;}
  
  $result = (Invoke-WebRequest -Uri &quot;https://www.ansiblet.com/api/v1/job_templates/{templateId}&quot; -Header $headers -Method GET -ContentType &quot;application/json&quot;).content | ConvertFrom-Json
  
  Write-Host $result
  }
  catch{
      echo $site = $_.Exception.response
  }
  </code></pre>
  <p>This web request isn't working.</p>
  <p>Response:</p>
  <pre><code>Name                           Value                                                                                                       
  ----                           -----                                                                                                       
  Token                          @{token=fcadd3e0326727e14f50401d4b8aaf91dc44ae47; expires=2018-09-14T12:30:11.546Z}                         
  Authorization                  Bearer                                                                                                      
  =
  
  IsMutuallyAuthenticated : False
  Cookies                 : {}
  Headers                 : {Transfer-Encoding, Connection, X-API-Time, Allow...}
  SupportsHeaders         : True
  ContentLength           : -1
  ContentEncoding         : 
  ContentType             : application/json
  CharacterSet            : 
  Server                  : nginx/1.10.2
  LastModified            : 9/14/2018 5:30:16 PM
  StatusCode              : Unauthorized
  StatusDescription       : UNAUTHORIZED
  ProtocolVersion         : 1.1
  ResponseUri             : https://www.ansiblet.com/api/v1/job_templates/1328/
  Method                  : GET
  IsFromCache             : False
  </code></pre>