LogoLogo
TwitterLinkedInGitHubPowerShell Gallery
  • About
  • Events
  • Blog
    • 2022
      • 🆕OSD January Update
      • 🆕PSCloudScript Basics
    • 2021
      • Start-OOBEDeploy
      • OSDCloud
      • PowerShell Gallery in WinPE
      • BitLocker KeyProtectors
      • WindowsCapability -and WindowsPackage
      • Scheduled Tasks
        • Building a Task
        • Task Permissions
        • Task Trigger
        • Action a PowerShell File
        • Action a PS Encoded Script
        • Conclusion
          • Windows Activation and Edition Change
          • REG.exe and Multiple Actions
    • 2019
      • 2019-02
        • Offline Servicing vs Reference Image
      • 2019-04
        • Windows 10 Upgrade MultiLang (Uno)
      • 2019-06
        • Offline Servicing Windows 10 with CU for .NET 4.8
        • OSDBuilder and .NET CU KB4480056
      • 2019-09
        • Black Screen During Windows 10 Setup
      • 2019-11
        • I Hate OSDBuilder
    • 2018
      • WinPE 10 1809 WPF DLL Fix
      • Microsoft Update Releases
      • Create WinPE.wim from Boot.wim or WinRE.wim
      • Windows Setup: FAT32 USB with +4GB Install.wim
      • Windows 10 from ESD
      • Windows 10 1809 Appx Issues
      • Mount-WindowsImage -Optimize
  • Guides
    • Autopilot App Registration
    • PSCloudScript
      • PS Cmdlets
      • GitHub Gist
      • GitHub Git Repo
      • Content-Type | Azure Static Web App
      • Command Shortening
      • Azure Key Vault Secret
      • OSD PowerShell Module
      • PSCloudScript Examples
        • Autopilot
        • AutopilotOOBE
        • OSDCloud Live
        • WinPE PowerShell Gallery
        • OSDCloud WinPE and OOBE
    • go OSDCloud
      • Azure Function
      • Custom Domain
      • SSL Binding
      • Proxies
  • PowerShell
    • OSD
    • OSDCloud
    • OSDBuilder (Offline Servicing)
    • OSDSUS (Update Catalogs)
    • OSDUpdate (MS Updates)
    • OSDDrivers (Compact Drivers)
    • PShot
      • Release Notes
      • Usage
        • -Directory
        • $AutoPath
        • -Prefix
        • -Count
        • -Delay
        • -Clipboard
        • -Primary
        • The Object
      • Technical
        • Why a Module?
        • Resolution, Scale and DPI
Powered by GitBook
On this page
  • Gist Editing in Visual Studio Code
  • Getting the Gist Raw URL
  • Gist Raw Commit URL
  • Gist Raw URL (Latest)
  • Get-GithubRawUrl
  • Execute the Gist
  • Sponsor
  1. Guides
  2. PSCloudScript

GitHub Gist

22.1.16

PreviousPS CmdletsNextGitHub Git Repo

Last updated 3 years ago

An easy way to get a PowerShell script online is by saving it in a GitHub Gist

In this example, I'll create and save a Public Gist. You can save it as a Private Gist, all that matters is that anyone with the URL has access, so don't consider it an option for saving Secure content like passwords

Once it is saved you should have the Git Editor URL

Gist Editing in Visual Studio Code

There are several Visual Studio Code extensions that can help you manage your GitHub gists, but one that really stands out is GistPad. It will be much easier to edit in VSCode with this and the PowerShell extension. You can add this from the Marketplace at this link

You will need to sign into your GitHub account and authorize Visual Studio Code to access GitHub

Getting the Gist Raw URL

You need to keep in mind that the URL shown for your Gist is one for the Gist Editor with your script in it, so you need to get the Raw URL by pressing the Raw button

Gist Editor URL Format
<Site>/<GitHubUser>/<Gist>

Gist Editor and Share URL
https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb

Gist Raw Commit URL

After pressing the Raw button on the Gist Editor page, you are redirected to the Raw Commit page. This URL for this page contains a commit string which means that it is static and the content will not reflect future changes that are made in the Gist Editor

Gist Raw Commit URL Format
<Site>/<GitHubUser>/<Gist>/raw/<Commit>/<ScriptName>

Gist Raw Commit URL
https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/5b683d468aaaecc2640669b82833bfa23f7da5ea/Test-PowerShellGist.ps1

Gist Raw URL (Latest)

To ensure you always have the latest content for your script, you need to remove the Commit string from the URL, so you will need to format your URL like this example. This is the URL you need to use for your PSCloudScript

Gist Raw URL Format
<Site>/<GitHubUser>/<Gist>/raw/<ScriptName>

Gist Raw URL
https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1

Get-GithubRawUrl

This function is part of the OSD PowerShell Module (version 22.1.15+) and it will return a GitHub Gist Raw URL for you automatically

PS C:\> Get-GithubRawUrl https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb
https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1

If your Gist has multiple files, those will be returned as well

PS C:\> Get-GithubRawUrl https://gist.github.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_ad_groups.ps1
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_az_db_restore.ps1
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_docker_container.md
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_install_on_ubuntu.sh
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_log_in_with_sp.ps1

I could have started with this function, but I to make sure you understand how to get the proper URL

Execute the Gist

Now that you have the proper Gist Raw URL, you can use execute the script using any of the following commands

iex (irm https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1)
irm https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1 | iex

#Requires OSD Module 22.1.15+
irm (Get-GithubRawUrl https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb) | iex
iex (irm (Get-GithubRawUrl https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb))

Sponsor

OSDeploy is sponsored by and their Systems Management Tools

Recast Software
Discover gistsGist
https://marketplace.visualstudio.com/items?itemName=vsls-contrib.gistfsmarketplace.visualstudio.com
HomeRecast Software
Sponsored by Recast Software
Logo
Logo