Skip to content

Instantly share code, notes, and snippets.

@bmkaiser
Last active October 5, 2020 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmkaiser/80fe54e1821c8ecd06f1c6fd774839e2 to your computer and use it in GitHub Desktop.
Save bmkaiser/80fe54e1821c8ecd06f1c6fd774839e2 to your computer and use it in GitHub Desktop.
Wrapper function to update PowerShell Stable and Preview channels
#Requires -Version 7.0
function Update-PowerShell {
[Alias('ups')]
param (
# THE POWERSHELL CHANNEL THAT YOU WANT TO INSTALL
[Parameter(Mandatory = $true)]
[ValidateSet(
'Stable',
'Preview'
ErrorMessage="Value '{0}' is invalid. Please use one of: '{1}'"
)]
[String]
$Channel
)
# STATIC PARAMETERS
$uri = 'https://aka.ms/install-powershell.ps1'
$params = @{
'UseMSI' = $true
'AddExplorerContextMenu' = $true
'EnablePSRemoting' = $true
'Quiet' = $true
}
$expression = "& {$(Invoke-RestMethod -Uri $uri)} @params"
switch ($PSBoundParameters['Channel']) {
Stable {
Invoke-Expression -Command $expression
}
Preview {
$params.Add('Preview',$true)
Invoke-Expression -Command $expression
}
Default {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment