I am trying to download a repo as a zip file using powershell. Below is how I am trying to do it.
$token = "MyGitToken"; $repo = "https://github.com/my-private-repo/archive/master.zip"; $targetFile = "./master.zip"; $restRequest = @{ Method = "Get" Uri = "$repo" Headers = @{ Authorization = "Token $token" Accept = "application/vnd.github.v3.raw" } }; $response = Invoke-RestMethod @restRequest -OutFile $targetFile; I am getting below error. Any idea how this can be fixed as suggested in the comments..
System.Net.WebException: The remote server returned an error: (406) Not Acceptable. at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request) at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord() PS: I am able to download the zip file when I directly hit the $repo url in a browser.
EDIT: Updated the Invoke-RestMethod command to use just OutFile instead of piping it.
Acceptheader. I can download a zip file from GitHub without it. Also,Invoke-RestMethodhas anOutFileparameter if you were unaware.OutFileparameter in my request. Thanks for the suggestion regarding Accept header. I removed it and I see the file getting downloaded...Out-Fileand not the included parameter withinInvoke-RestMethod. There is no need to pipe it to the next cmdlet. Glad you got your issue fixed anyway.