Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Last active July 9, 2022 06: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 JustinGrote/b207e37310f48148e7c121158254eca9 to your computer and use it in GitHub Desktop.
Save JustinGrote/b207e37310f48148e7c121158254eca9 to your computer and use it in GitHub Desktop.
PowerShell Bootstrap Script
<#
.SYNOPSIS
Install PowerShell on Windows, Linux or macOS.
#>
[CmdletBinding(SupportsShouldProcess)]
param(
#Where PowerShell should be installed.
[string]$Destination,
#The version to install. Default is the latest stable version. Additional Options are a LTS, Preview, Daily, or a specific version number tag.
[ValidateNotNullOrEmpty][string]$Version = 'Stable'
)
Set-StrictMode -Version 3.0
# Setting Tls to 12 to prevent the Invoke-WebRequest : The request was
# aborted: Could not create SSL/TLS secure channel. error.
$originalValue = [Net.ServicePointManager]::SecurityProtocol
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$metadataUri = 'https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json'
$metadata = Invoke-RestMethod -UseBasicParsing $metadataUri
$tag = switch ($Version) {
'Stable' {
$metadata.PSData.StableVersion -replace '^v'
}
'Preview' {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment