@@ -7,8 +7,7 @@ branding:
77
88inputs :
99 Version :
10- description : The version of PowerShell to install, i.e. 7.4.0 or 7.5.0. If not provided it, latest version is installed.
11- required : false
10+ description : The version of PowerShell to install, e.g., 7.4.0 or 7.5.0. If not provided, the latest version is installed.
1211 default : ' '
1312
1413runs :
@@ -19,12 +18,46 @@ runs:
1918 shell : powershell
2019 run : |
2120 $version = '${{ inputs.version }}'
22- winget uninstall --id Microsoft.PowerShell --accept-source-agreements --accept-package-agreements
21+
22+ # Try to remove existing PowerShell installation
23+ try {
24+ # Find existing PowerShell installations to remove
25+ Get-Package -Name "PowerShell*" -ErrorAction SilentlyContinue | ForEach-Object {
26+ Write-Host "Uninstalling $($_.Name) version $($_.Version)"
27+ Uninstall-Package -Name $_.Name -Force -ErrorAction SilentlyContinue
28+ }
29+ } catch {
30+ Write-Host "Error removing existing PowerShell: $_"
31+ }
32+
33+ # Get the version to install
2334 if ([string]::IsNullOrWhiteSpace($version)) {
24- winget install --id Microsoft.PowerShell --source winget --accept-package-agreements --accept-source-agreements
35+ # Get latest version from GitHub API
36+ $releaseInfo = Invoke-RestMethod -Uri 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest'
37+ $version = $releaseInfo.tag_name.Trim('v')
38+ Write-Host "Latest PowerShell version: $version"
39+ } else {
40+ Write-Host "Installing specified PowerShell version: $version"
2541 }
26- else {
27- winget install --id Microsoft.PowerShell --version $version --source winget --accept-package-agreements --accept-source-agreements
42+
43+ # Download and install PowerShell
44+ $msiName = "PowerShell-$version-win-x64.msi"
45+ $downloadUrl = "https://github.com/PowerShell/PowerShell/releases/download/v$version/$msiName"
46+
47+ Write-Host "Downloading from $downloadUrl"
48+ Invoke-WebRequest -Uri $downloadUrl -OutFile $msiName
49+
50+ Write-Host "Installing PowerShell $version"
51+ Start-Process -FilePath "msiexec.exe" -ArgumentList "/i", $msiName, "/quiet", "/norestart" -Wait
52+
53+ # Verify installation
54+ $pwshPath = "$env:ProgramFiles\PowerShell\7\pwsh.exe"
55+ if (Test-Path $pwshPath) {
56+ Write-Host "PowerShell installed successfully:"
57+ & $pwshPath -Command '$PSVersionTable'
58+ } else {
59+ Write-Error "PowerShell installation failed. Could not find $pwshPath"
60+ exit 1
2861 }
2962
3063 - name : Install PowerShell on Ubuntu
0 commit comments