Skip to content

Instantly share code, notes, and snippets.

@kilasuit
Last active September 20, 2023 01:44
Show Gist options
  • Save kilasuit/694d3946f2062b0bcf255c13b3ba2bfa to your computer and use it in GitHub Desktop.
Save kilasuit/694d3946f2062b0bcf255c13b3ba2bfa to your computer and use it in GitHub Desktop.
Examples of using the install-powershell.ps1 script from the PowerShell Repo
# Requires -Version 3.0
# This script shows how to install multiple versions of PowerShell using Start-Job which allows for parallel installs of the zip package of PowerShell on your system & will work when run in PowerShell 3.0 or higher.
$destination = "-Destination 'C:\ps'" # Comment out this line to install in current users local appdata folder instead.
# Eventually this line will be simplified by going back to the https://aka.ms/install-powershell.ps1 link instead but is waiting on this [PR](https://github.com/PowerShell/PowerShell/pull/19884/) to be merged
$scriptURL = 'https://raw.githubusercontent.com/kilasuit/PowerShell/update-install-powershell-script/tools/install-powershell.ps1'
$IEXScriptBlock_Part1 = "& {$(Invoke-RestMethod $scriptURL)}"
$versions = @(
"7.4.0-preview.2",
"7.3.2",
"7.3.1",
"7.2.8",
"7.4.preview.3" # Intentionally wrong as to show how the script errors
)
foreach ($version in $versions) {
$scriptblock = "$IEXScriptBlock_Part1 -Version $version $destination"
Start-Job -Name $version -ScriptBlock { Invoke-Expression $using:scriptblock}
}
Get-Job | Wait-Job | Receive-Job | Remove-Job
# Requires -Version 3.0
# This script shows how to install multiple versions of PowerShell using Start-Job which allows for parallel installs of the zip package of PowerShell on your system & should work when run in PowerShell 3.0 or higher.
$destination = "-Destination 'C:\ps'" # Comment out this line to install in current users local appdata folder instead.
# Eventually this line will be simplified by going back to the https://aka.ms/install-powershell.ps1 link instead but is waiting on this [PR](https://github.com/PowerShell/PowerShell/pull/19884/) to be merged
$scriptURL = 'https://raw.githubusercontent.com/kilasuit/PowerShell/update-install-powershell-script/tools/install-powershell.ps1'
$IEXScriptBlock_Part1 = "& {$(Invoke-RestMethod $scriptURL)}"
# Gets the latest 30 released of PowerShell from GitHub (this check is used in the install-powershell.ps1 script)
$releaseVersions = Invoke-RestMethod https://api.github.com/repos/PowerShell/PowerShell/releases -Verbose:$false
$versions = $releaseVersions | Select-object tag_name,created_at | Out-GridView -Title "Select PowerShell Versions to Install" -PassThru | Select-Object -ExpandProperty tag_name
foreach ($version in $versions) {
$scriptblock = "$IEXScriptBlock_Part1 -Version $version $destination"
Start-Job -Name $version -ScriptBlock { Invoke-Expression $using:scriptblock}
}
Get-Job | Wait-Job | Receive-Job | remove-job
# This example Script gives you lots of different ways to install the following random matrix of PowerShell versions
## It is **NOT** intended to be run as a script however will work
## It is however intended as a reference for how to install different versions of PowerShell in different ways
## to the Install-PowerShell.ps1 Readme file https://github.com/PowerShell/PowerShell/blob/master/tools/install-powershell.ps1-README.md
# Daily
# Stable
# Preview
# LTS
# 7.4.0-preview.4
# 7.3.4
# 7.3.3
# 7.2.10
#
# All versions will be side by side installed in C:\ (So needs to be run as admin)
# However, you can change the destination folder by changing the -destination parameter as that you can install it anywhere you want instead
# If you don't provide a destination it will install in current users local appdata folder (on Windows that is C:\Users\username\AppData\Local\) or will install in "~/.powershell" on Linux and macOS
$destination = "-Destination 'C:\ps'" # Comment out this line to install in current users local appdata folder instead.
# Eventually this line will be simplified by going back to the https://aka.ms/install-powershell.ps1 link instead but is waiting on this [PR](https://github.com/PowerShell/PowerShell/pull/19884/) to be merged
$scriptURL = 'https://raw.githubusercontent.com/kilasuit/PowerShell/update-install-powershell-script/tools/install-powershell.ps1'
$IEXScriptBlock_Part1 = "& {$(Invoke-RestMethod $scriptURL)}"
# Daily
$DailyScriptBlock = "$IEXScriptBlock_Part1 -daily $destination"
Start-Job -Name Daily -ScriptBlock { Invoke-Expression $using:DailyScriptBlock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -daily -destination $Destination"
# invoke-expression "& {$(Invoke-RestMethod https://raw.githubusercontent.com/kilasuit/PowerShell/update-install-powershell-script/tools/install-powershell.ps1)} -daily -destination 'C:\ps'"
# Stable
$StableScriptBlock = "$IEXScriptBlock_Part1 -Stable $destination"
Start-Job -Name Daily -ScriptBlock { Invoke-Expression $using:StableScriptBlock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -Stable -destination $Destination"
# Invoke-Expression "& {$(Invoke-RestMethod https://raw.githubusercontent.com/kilasuit/PowerShell/update-install-powershell-script/tools/install-powershell.ps1)} -Stable -destination 'C:\ps'"
# Preview
$PreviewScriptBlock = "$IEXScriptBlock_Part1 -Preview $destination"
Start-Job -Name Daily -ScriptBlock { Invoke-Expression $using:PreviewScriptBlock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -Preview -destination $Destination"
# Invoke-Expression "& {$(Invoke-RestMethod https://raw.githubusercontent.com/kilasuit/PowerShell/update-install-powershell-script/tools/install-powershell.ps1)} -Preview -destination 'C:\ps'"
# LTS
$ltsScriptBlock = "$IEXScriptBlock_Part1 -LTS $destination"
Start-Job -Name LTS -ScriptBlock { Invoke-Expression $using:ltsScriptBlock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -LTS -destination $Destination"
# 7.4.0-preview.4
$v740preview4ScriptBlock = "$IEXScriptBlock_Part1 -Version v7.4.0-preview.4 $destination"
Start-Job -Name v740preview4 -ScriptBlock { Invoke-Expression $using:v740preview4ScriptBlock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -Version v7.4.0-preview.4 -destination $Destination"
# 7.3.4
$v734scriptblock = "$IEXScriptBlock_Part1 -Version v7.3.4 $destination"
Start-Job -Name v734 -ScriptBlock { Invoke-Expression $using:v734scriptblock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -Version v7.3.4 -destination $Destination"
# 7.2.10
$v7210scriptblock = "$IEXScriptBlock_Part1 -Version v7.2.10 $destination"
Start-Job -Name v7210 -ScriptBlock { Invoke-Expression $using:v7210scriptblock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -Version v7.2.10 -destination $Destination"
$v733scriptblock = "$IEXScriptBlock_Part1 -Version v7.3.3 $destination"
Start-Job -Name v733 -ScriptBlock { Invoke-Expression $using:v733scriptblock}
# Invoke-Expression "& {$(Invoke-RestMethod $scriptURL)} -Version v7.3.3 -destination $Destination"
# Wait for all jobs to finish
Get-Job | Wait-Job | Receive-Job | Remove-Job
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment