Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Creating a Github Gist with PowerShell

Posted on January 26, 2017

Recently I posted a PowerShell tool for creating a GitHub repository. In continuing my exploration of the GitHub API I wrote another PowerShell tool to create a GitHub gist. A gist is simple way to store and share snippets or code samples. I use them to share simple PowerShell scripts or other works that aren't full blown multi-file modules. Now I can create these gists directly from PowerShell and the PowerShell ISE.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

As in my repo tool, you will need to know your Github token. My previous article has information about it if you missed it. Once you have that, then you can use this function, which is conveniently stored as a Github gist.

https://gist.github.com/jdhitsolutions/06cb62bf3eb4f0a1f7d82ed39b1e56ca

The function will create a gist from content you pass or you can specify a file name and the command will use that content. You will have to specify a name for your gist and you will need your token. I've also included an option to create a private gist which I believe requires a paid account.

With this function I can easily create a gist from an existing file.

New-GitHubGist -Name "BoxPrompt.ps1" -Description "a fancy PowerShell prompt function" -Path S:\boxprompt.ps1

You can see that gist here. If you use -Passthru you will get a custom object which includes the url.

image

But I also wanted an easy way to take a snippet from the PowerShell ISE and create a gist so I wrote this:

https://gist.github.com/jdhitsolutions/345a6b8e4c47440df5fb1dbcb987cb3e

This code includes commands to add short cut menus to the ISE.

image

You can select a block of code in the PowerShell ISE and then click one of these options. You will be prompted in the console pane to provide a filename and description.

What I don't have now is a good way to update an existing gist or delete them from PowerShell. The GitHub API supports these concepts but I haven't gotten that far.

In the mean time, I hope you'll give these commands a try and let me know what you think.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

3 thoughts on “Creating a Github Gist with PowerShell”

  1. Xavier Plantefève says:
    January 26, 2017 at 11:08 am

    I wrote a module to manipulate gists a while ago. It includes an update function: https://gist.github.com/XPlantefeve/5e85af5998abf08f2d86c9aef968ef9f

    Feel free to use it as an inspiration as to what you think it should look like. Feel free to critic the code as well, it was my “let’s learn to code a module/let’s learn to use an API” moment.

  2. Jesper says:
    January 28, 2017 at 3:32 pm

    Thank you!

  3. Francis Setash says:
    February 2, 2017 at 3:29 pm

    Awesome; I really like this – come to think of it I’m kinda shocked I haven’t happened upon a VS Code extension that builds this ability in (maybe it’s there, but I haven’t seen it yet).

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d