Automating the GitHub REST API Using PowerShell

Play Automating the GitHub REST API Using PowerShell
Sign in to queue


Have you always wondered how to interact with REST APIs using PowerShell? If so, then wonder no more! During this video demonstration, we will take a look at using PowerShell's powerful Invoke-RestMethod command to call REST APIs! GitHub's interface is actually quite easy to use, because they support HTTP Basic Authentication, using pre-generated Personal Access Tokens. You don't need to worry about the oAuth authentication flow by using these special tokens! Even better, these tokens enable you to restrict which operations each token can perform, so even if one token is compromised, the scope of damage can be somewhat limited.

Throughout this video, we'll perform several common operations on GitHub, using their REST API from PowerShell:

  • Authenticate using Personal Access Tokens
  • Create new GitHub repositories
  • Delete existing GitHub repositories
  • Make updates to our GitHub user profile

This video was recorded and produced using PowerShell version 5.0 on Windows 10 RTM version 1511 by Trevor Sullivan, a Microsoft MVP for Windows PowerShell. Visit Trevor's website at and follow him on Twitter @pcgeek86. Thanks for watching!

IMPORTANT: Personal Access Tokens were harmed in the creation of this video. If this is a problem for you, then you are probably too close to your Personal Access Tokens.



Right click to download this episode

The Discussion

  • User profile image

    Very interesting and informative THANK YOU !

  • User profile image

    @MChorfa: Thanks for your feedback, MChorfa!

  • User profile image
    Michael Maher

    Thanks for sharing Trevor. Can I ask about the @Headers hash table. I know you said the Authorization string needs to be Basic followed by a space.

    Is that what the zero in code blocks does?

    I'm also wondering what function the -f parameter in this hash table performs.


  • User profile image

    @Michael Maher: Hey Michael! Thanks for the feedback. Check out .NET string formatting! That's what the the -F operator is. The {0} is used as a substitution.

  • User profile image
    Michael Maher

    Ok got it.

    I found this article which walks through it well.

    Halfway down the page - Using .NET to Format Numbers in Windows PowerShell

  • User profile image

    Hi! Good video! Is it essential to have a video of you talking in the bottom right corner. Its in the way of the code. If that's a must have ,couldn't it be in the top right corner or make it smaller. / Fabio

  • User profile image

    @sup3r7:Thanks for the feedback, Fabio. I do see where the code was cut off towards the end, and I didn't intend for that. Next time I'll try to make it better. :)

    Trevor Sullivan

  • User profile image

    @Michael Maher: Exactly! You've got it, mate. It's a very powerful concept, if you spend a bit of time grasping it! I primarily use it for simple substitution, but it can do much, much more. In fact, you can even write your own custom formatters!

  • User profile image

    I am new to GitHub
    Very good video and so clear instructions. Thanks for sharing it.

Add Your 2 Cents