Last active
July 24, 2020 09:20
-
-
Save Alex-Yates/46da822dd788672eb3b990fd3e08474b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-Script{ | |
param ( | |
[Parameter(Mandatory=$true)][string]$script, # the name of the file (needs to be in repo root, otherwise tweak this function) | |
[string]$owner = "my-username", # repo owner (github username) | |
[string]$repo = "my-repo", # name of repo | |
[string]$branch = "master", | |
[string]$outputDir = "" | |
) | |
# the raw page for the script | |
$uri = "https://raw.githubusercontent.com/$owner/$repo/$branch/$script" | |
# choosing a default output directory if none specified | |
if ($outputDir -like "") { | |
$currentDir = Get-Location | |
$outputDir = "$currentDir\$repo" | |
} | |
# ensuring the output directory exists | |
if ((test-path $outputDir) -ne $true) { | |
Write-Output " Creating directory $outputDir" | |
New-Item -ItemType "Directory" -Path $outputDir | Out-Null | |
} | |
# logging | |
Write-Output "Downloading $script" | |
Write-Output " from: $uri" | |
Write-Output " to: $outputDir" | |
# reading the page and saving to file | |
Invoke-WebRequest -Uri $uri -OutFile $outFile -Verbose | |
} | |
# Example execution: | |
# Get-Script -script "my-script.ps1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment