From 582d23c88456b26178fdaf1d39678dd7a30a8ed1 Mon Sep 17 00:00:00 2001 From: Alexey-Ayupov <116575425+Alexey-Ayupov@users.noreply.github.com> Date: Fri, 18 Nov 2022 20:16:09 +0100 Subject: [PATCH] [Windows] Pin PowerShell version 7.2.7 (#6591) --- .../Installers/Install-PowershellCore.ps1 | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-PowershellCore.ps1 b/images/win/scripts/Installers/Install-PowershellCore.ps1 index f968ebf9..c0f7208e 100644 --- a/images/win/scripts/Installers/Install-PowershellCore.ps1 +++ b/images/win/scripts/Installers/Install-PowershellCore.ps1 @@ -3,7 +3,35 @@ ## Desc: Install PowerShell Core ################################################################################ -Invoke-Expression "& { $(Invoke-RestMethod https://aka.ms/install-powershell.ps1) } -UseMSI -Quiet" +$ErrorActionPreference = "Stop" + +$tempDir = Join-Path ([System.IO.Path]::GetTempPath()) ([System.IO.Path]::GetRandomFileName()) +$null = New-Item -ItemType Directory -Path $tempDir -Force -ErrorAction SilentlyContinue +try { + $originalValue = [Net.ServicePointManager]::SecurityProtocol + [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 + + $metadata = Invoke-RestMethod https://raw.githubusercontent.com/PowerShell/PowerShell/master/tools/metadata.json + $release = $metadata.LTSReleaseTag[0] -replace '^v' + $packageName = "PowerShell-${release}-win-x64.msi" + + $downloadURL = "https://github.com/PowerShell/PowerShell/releases/download/v${release}/${packageName}" + Write-Verbose "About to download package from '$downloadURL'" -Verbose + + $packagePath = Join-Path -Path $tempDir -ChildPath $packageName + Invoke-WebRequest -Uri $downloadURL -OutFile $packagePath + + Write-Verbose "Performing quiet install" + $ArgumentList=@("/i", $packagePath, "/quiet") + $process = Start-Process msiexec -ArgumentList $ArgumentList -Wait -PassThru + if ($process.exitcode -ne 0) { + throw "Quiet install failed, please rerun install without -Quiet switch or ensure you have administrator rights" + } +} finally { + # Restore original value + [Net.ServicePointManager]::SecurityProtocol = $originalValue + Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue +} # about_update_notifications # While the update check happens during the first session in a given 24-hour period, for performance reasons,