Last active
July 9, 2022 06:07
-
-
Save JustinGrote/b207e37310f48148e7c121158254eca9 to your computer and use it in GitHub Desktop.
PowerShell Bootstrap Script
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
<# | |
.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