GitHub Gist
22.1.16
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
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

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

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
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

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
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))


Home
Recast Software
Sponsored by Recast Software
Last modified 1yr ago