Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

Downloading a file from github enterprise (authenticated/ssl) on Windows using Powershell

I need to download a script from github but I don't have git on the windows machines, on Linux I just used curl -u, for windows it needed more than a one liner.
Here's what I came up with, we have self signed certs so I need to fool System.Net into thinking all certs are good, that's a one liner:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

Next I create a WebClient object and set two headers:

$client = New-Object System.Net.WebClient
$client.Headers.Add("Authorization","token 1234567890notarealtoken987654321")
$client.Headers.Add("Accept","application/vnd.github.v3.raw")

I set up an OAuth token for github earlier, so I set that as my authorization to login to github enterprise. The second header tells github that I'm ok with raw files (if you don't do this, you get back a json)

Finally, I download the file.

$client.DownloadFile("https://github.company.com/api/v3/repos/me/my_repo/contents/test/test-script.ps1?ref=branch_I_need","C:\temp\test-script.ps1”)

You can probably roll this up into a one liner and get rid of the $client object, but this is much more readable. Here's everything together.


[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$client = New-Object System.Net.WebClient
$client.Headers.Add("Authorization","token 1234567890notarealtoken987654321")
$client.Headers.Add("Accept","application/vnd.github.v3.raw")
$client.DownloadFile("https://github.company.com/api/v3/repos/me/my_repo/contents/test/test-script.ps1?ref=branch_I_need","C:\temp\test-script.ps1”)

A little more work than

curl -u me -k https://github.company.com/api/v3/repos/me/my_repo/contents/test/test-script.ps1 >test-script.ps1

Wordpress category: 

Add new comment

Markdown

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.