49

PowerShell: Download script or file from GitHub - Thomas Maurer

 2 years ago
source link: https://www.thomasmaurer.ch/2021/07/powershell-download-script-or-file-from-github/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Written by Thomas Maurer• July 27, 2021• 7:13 am• PowerShell

PowerShell: Download script or file from GitHub

HomePowerShellPowerShell: Download script or file from GitHub

Since a lot of people are starting to store their scripts and files in GitHub repositories, I often get the question, how can I download a script or a file from a Git repository using PowerShell. There are a couple of ways to you can obviously do this. You could use git and do a git clone of the repository and then run the script. In many cases however you don’t have git installed on the machine or it would be too much to clone the whole repo. So you can simply download the file or script from GitHub using PowerShell using the Invoke-WebRequest cmdlet.

Invoke-WebRequest -Uri https://raw.githubusercontent.com/thomasmaurer/demo-cloudshell/master/helloworld.ps1 -OutFile .\helloworld.ps1

This download my HelloWorld.ps1 PowerShell example file from the following example repository on GitHub.

You can also create the following one-liner which directly starts the PowerShell file using chaining in PowerShell.

Invoke-WebRequest -Uri https://raw.githubusercontent.com/thomasmaurer/demo-cloudshell/master/helloworld.ps1 -OutFile .\helloworld.ps1; .\helloworld.ps1 

You can learn more about PowerShell chain operators in my blog post here.

I hope this quick blog post on how to download scripts or files from GitHub using PowerShell was helpful. If you have any questions, feel free to leave a comment below.

Email address:

Leave this field empty if you're human:

Tags: download, file, GitHub, Microsoft, PowerShell, script


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK