File tree Expand file tree Collapse file tree 1 file changed +18
-10
lines changed
Expand file tree Collapse file tree 1 file changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -37,16 +37,24 @@ runs:
3737 $currentVersion = $currentInstall.Version
3838 Write-Host "Current PowerShell version: $currentVersion"
3939
40- # Compare versions
41- if ([System.Version]$currentVersion -ge [System.Version]$version) {
42- Write-Host "Current version is greater than or equal to target version. Skipping installation."
43- $needToInstall = $false
44- } else {
45- Write-Host "Current version is lower than target version. Will upgrade."
46-
47- # Uninstall current version
48- Write-Host "Uninstalling $($currentInstall.Name) version $($currentInstall.Version)"
49- Uninstall-Package -Name $currentInstall.Name -Force -ErrorAction SilentlyContinue
40+ # Parse versions into System.Version objects for proper comparison
41+ try {
42+ $currentVersionObj = [System.Version]$currentVersion
43+ $targetVersionObj = [System.Version]$version
44+
45+ # Compare versions
46+ if ($currentVersionObj -ge $targetVersionObj) {
47+ Write-Host "Current version $currentVersion is greater than or equal to target version $version. Skipping installation."
48+ $needToInstall = $false
49+ } else {
50+ Write-Host "Current version $currentVersion is lower than target version $version. Will upgrade."
51+
52+ # Uninstall current version
53+ Write-Host "Uninstalling $($currentInstall.Name) version $($currentInstall.Version)"
54+ Uninstall-Package -Name $currentInstall.Name -Force -ErrorAction SilentlyContinue
55+ }
56+ } catch {
57+ Write-Host "Error comparing versions: $_. Will proceed with installation."
5058 }
5159 } else {
5260 Write-Host "PowerShell Core not found. Will install version $version"
You can’t perform that action at this time.
0 commit comments