GitHub Gist
22.1.16
An easy way to get a PowerShell script online is by saving it in a GitHub Gist
Discover gists
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
https://marketplace.visualstudio.com/items?itemName=vsls-contrib.gistfs
marketplace.visualstudio.com
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
1
Gist Editor URL Format
2
<Site>/<GitHubUser>/<Gist>
3
4
Gist Editor and Share URL
5
https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb
Copied!

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
1
Gist Raw Commit URL Format
2
<Site>/<GitHubUser>/<Gist>/raw/<Commit>/<ScriptName>
3
4
Gist Raw Commit URL
5
https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/5b683d468aaaecc2640669b82833bfa23f7da5ea/Test-PowerShellGist.ps1
Copied!

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
1
Gist Raw URL Format
2
<Site>/<GitHubUser>/<Gist>/raw/<ScriptName>
3
4
Gist Raw URL
5
https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1
Copied!

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
1
PS C:\> Get-GithubRawUrl https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb
2
https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1
Copied!
If your Gist has multiple files, those will be returned as well
1
PS C:\> Get-GithubRawUrl https://gist.github.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6
2
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_ad_groups.ps1
3
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_az_db_restore.ps1
4
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_docker_container.md
5
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_install_on_ubuntu.sh
6
https://gist.githubusercontent.com/MartinLuksik/a9902abc12aa831ef6719d15b5d24ac6/raw/pwsh_log_in_with_sp.ps1
Copied!
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
1
iex (irm https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1)
2
irm https://gist.githubusercontent.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb/raw/Test-PowerShellGist.ps1 | iex
3
4
#Requires OSD Module 22.1.15+
5
irm (Get-GithubRawUrl https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb) | iex
6
iex (irm (Get-GithubRawUrl https://gist.github.com/OSDeploy/f43c96be58e09f20d1407c44a49721fb))
Copied!

Sponsor

OSDeploy is sponsored by Recast Software and their Systems Management Tools
Home
Recast Software
Sponsored by Recast Software