title: Powershell invoke WebRequest with NTLM for a post
body: <h2>INITIAL QUESTION</h2>
  
  <p>How Can I perform Invoke-WebRequest or similar, with Powershell so that NTLM authentication is used but also supply a body for a post. </p>
  
  <h2>EXAMPLE</h2>
  
  <p>The code sample below is my example post using invoke web request and pipes response out to a .json file. Username and Password Variable not included in example.</p>
  
  <pre><code>$myURL = https://example.blah.etc
  $params = @" {""EXAMPLE1":"STUFF"} "@ 
  
  $Headers = @{ Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Username,$Password))) }
  
  
  Invoke-WebRequest -Uri $myURL  -Headers $Headers -Method POST -ContentType "application/json" -Body  $params  | Select-Object -ExpandProperty Content &gt; "C:\output.json"
  </code></pre>
  
  <h2>UPDATE</h2>
  
  <p>Using -UseDefaultCredentials only works for Gets, not for posts. </p>
  
  <hr>
  
  <hr>
  
  <h2>ERROR RESPONSE</h2>
  
  <p>The remote server returned an error: (401) Unauthorized</p>