title: Powershell: Out-File - Access to the path is denied
body: <p>I've got a REST call (POST) for downloading a PDF file. The API call responds in a binary version of the PDF file. I want to save the file on my machine as a .pdf. However, I am getting an error:</p>
  <pre>
  Out-File : Access to the path 'C:\Users\my-name\Documents\Tests' is denied.
  At C:\Users\my-name\Documents\Tests\TEST-WITH-LOOP.ps1:132 char:149
  + ... questBody | Out-File -FilePath ("C:\Users\my-name\Documents\Tests
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : OpenError: (:) [Out-File], UnauthorizedAccessException
      + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
  </pre>
  <p>Response body header from POSTMAN:</p>
  <pre>
  Content-Disposition →attachment; filename="Report-01_29_14-28.pdf"
  Content-Type →application/octet-stream
  DataServiceVersion →2.0
  Date →Mon, 29 Jan 2018 21:51:31 GMT
  Date →Mon, 29 Jan 2018 21:51:31 GMT
  Server →Jetty(9.3.7.v20160115NeotysEdition.30)
  Transfer-Encoding →chunked
  </pre>
  <p>Command:</p>
  <pre><code>$DownloadReportResponse = Invoke-RestMethod -Method Post -Uri $DownloadReportUrl -ContentType &quot;application/json&quot; -Body $DownloadReportRequestBody |
      Out-File -FilePath (&quot;C:\Users\my-name\Documents\Tests&quot;) -Force
  </code></pre>
  <p><strong>Question:</strong>
  How do I save this to my machine as a .pdf or possibly include as an attachment to the email?</p>