Search code examples
powershellgithubcode-snippetsgist

How to upload/download/edit a Gist with PowerShell


I have been trying to find methods to upload code to Gist (returning the id/url of the created Gist to be able to reference, both anonymously and publicly/privately using a git account) and to be able download/edit the contents/description of those Gists from the commandline natively with PowerShell.

There are various good solutions for this for other environments (this question, for example, is very similar in scope but for bash, and the answers there cover bash, python, ruby etc Upload a file to a Gist with bash). I would appreciate pointers or solutions for this as in many searches elsewhere I have found no working methods to natively achieve something like this with PowerShell. Being able to upload/download/edit/share code as Gists similar to that question (but natively with PowerShell on Windows) would be of broad usefulness I think.


Solution

  • You might use the Posh-Gist module as starting point.

    In short: Gists are created via Rest API, in powershell you use the invoke-restmethod cmdlet.

    Github provides a Rest API, which is well documented.