The following script will automatically download and install the latest x86 version of PowerShell 7.
# Upgrade-PowerShell.ps1
# REF: https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/resolving-urls-3
#requires -version 7.0
$Params = @{
Method = 'HEAD'
Uri = 'https://github.com/PowerShell/PowerShell/releases/latest'
MaximumRedirection = 0
ErrorAction = 'SilentlyContinue'
SkipHttpErrorCheck = $true
}
$latestReleaseUri = (Invoke-WebRequest @Params).Headers.Location
$version = (Split-Path $latestReleaseUri -Leaf).Substring(1)
$platform = 'x86'
$packageName = "PowerShell-$version-win-$platform.msi"
$downloadUri = "$($latestReleaseUri -replace 'tag','download')/$packageName"
"Downloading latest release of PowerShell from:`r`n$downloadUri"
$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName())
$null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue
$packagePath = Join-Path -Path $tempDir -ChildPath $packageName
Invoke-WebRequest -Uri $downloadUri -OutFile $packagePath
#REF: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2
#REF: https://github.com/PowerShell/PowerShell/blob/master/tools/install-powershell.ps1
#ARG REF: ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1 ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1 ENABLE_PSREMOTING=1
#ARG REF: REGISTER_MANIFEST=1 USE_MU=1 ENABLE_MU=1
$MSIArguments = @('/i', $packagePath, 'REGISTER_MANIFEST=1', 'USE_MU=1', 'ENABLE_MU=1')
Start-Process msiexec.exe -ArgumentList $MSIArguments -Verb 'RunAs' -Wait