Skip to content

Commit aedf251

Browse files
Implement Windows PowerShell downgrade support using msiexec /f flag
Co-authored-by: MariusStorhaug <[email protected]>
1 parent 2a7b393 commit aedf251

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

action.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,41 @@ runs:
204204
exit 0
205205
}
206206
207+
# Check if we need to handle a downgrade scenario
208+
$isDowngrade = $false
209+
if ($detected -and $detected -ne $env:REQUESTED_VERSION) {
210+
try {
211+
$detectedVersion = [version]$detected
212+
$requestedVersion = [version]$env:REQUESTED_VERSION
213+
if ($detectedVersion -gt $requestedVersion) {
214+
Write-Host "Downgrade detected: $detected → $($env:REQUESTED_VERSION)"
215+
$isDowngrade = $true
216+
} else {
217+
Write-Host "Upgrade detected: $detected → $($env:REQUESTED_VERSION)"
218+
}
219+
} catch {
220+
Write-Host "Warning: Could not compare versions, proceeding with installation"
221+
}
222+
}
223+
207224
$msi = "PowerShell-$($env:REQUESTED_VERSION)-win-x64.msi"
208225
$url = "https://github.com/PowerShell/PowerShell/releases/download/v$($env:REQUESTED_VERSION)/$msi"
209226
Write-Host "Downloading from: $url"
210227
211-
Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..."
212-
213228
if (-not (Invoke-WebRequest -Uri $url -OutFile $msi -UseBasicParsing -PassThru)) {
214229
Write-Host "Error: Failed to download PowerShell package"
215230
exit 1
216231
}
217-
Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait
232+
233+
Write-Host "Starting installation of PowerShell [$($env:REQUESTED_VERSION)]..."
234+
235+
if ($isDowngrade) {
236+
# For downgrades, use force reinstall to overwrite the existing version
237+
Write-Host "Using force reinstall for downgrade scenario..."
238+
Start-Process msiexec.exe -ArgumentList '/f', $msi, '/quiet', '/norestart' -Wait
239+
} else {
240+
# For upgrades or fresh installs, use regular install
241+
Start-Process msiexec.exe -ArgumentList '/i', $msi, '/quiet', '/norestart' -Wait
242+
}
218243
219244
Write-Host "Installation complete. PowerShell [$($env:REQUESTED_VERSION)] is now available."

0 commit comments

Comments
 (0)