Windows: Assuming that PowerShell Core is not installed on Windows
scenario.
Linux : Assuming that PowerShell Core was not installed by default and need to make a shell script to install it
scenario.
MacOS : Assuming that Tried other method to download latest PS Core than Microsoft provided script, but failed. Removing the files, but found leftovers that must be removed by the script
How to download and install latest PowerShell Core
of a specified channel (release , beta, rc)
for specified OS (-win- ; -osx ; -1.ubuntu-18.04-)
with specified architecture (-amd64 ; -x86 ; -x64)
using bash or powershell? (Without requiring manual config)
Here's the code :
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$location = Get-Location
$architecture = "x" + (Get-WmiObject Win32_Processor).AddressWidth
$assetName = "PowerShell-*-win-$architecture.msi"
$gitHubApi = 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest'
$response = Invoke-WebRequest -Uri $gitHubApi -UseBasicParsing
$json = $response.Content | ConvertFrom-Json
$release = $json.assets | Where-Object Name -like $assetName
Invoke-WebRequest $release.browser_download_url -OutFile "$location\$($release.name)"
Start-Process msiexec.exe -Wait -ArgumentList '/A $($release.name) /I $location\$($release.name) /quiet /qb ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 REGISTER_MANIFEST=1 ENABLE_PSREMOTING=1'
Write-Host Ok