Skip to content

[Bug Report] Fix WinUtil installer to handle PowerShell MSI installations automatically #4977

Description

@KrzysiekSko

Problem

WinUtil recommends winget upgrade Microsoft.PowerShell. When PowerShell was installed via the MSI at C:\Program Files\PowerShell\7\pwsh.exe, the upgrade fails with:

A newer version was found, but the install technology is different from the current version installed.

Proposed Fix

Detect MSI-installed PowerShell, query the latest release from the PowerShell GitHub API, download the matching PowerShell*-win-x64.msi, run it silently, and remove the temporary installer afterward.

Suggested flow:

$Current = (Get-Command pwsh -ErrorAction SilentlyContinue).Source
if ($Current -like "C:\Program Files\PowerShell\7\pwsh.exe") {
    $Release = Invoke-RestMethod "https://api.github.com/repos/PowerShell/PowerShell/releases/latest"
    $Asset = $Release.assets |
        Where-Object name -match '^PowerShell-.*-win-x64\.msi$' |
        Select-Object -First 1
    $Msi = Join-Path $env:TEMP $Asset.name
    Invoke-WebRequest $Asset.browser_download_url -OutFile $Msi
    Start-Process msiexec.exe -ArgumentList "/i `"$Msi`" /passive /norestart" -Wait
    Remove-Item $Msi -Force
}
else {
    winget upgrade Microsoft.PowerShell
}

This should support future PowerShell versions, require no manual download, preserve the MSI-based installation method, and avoid the recurring winget error.

How to test

  1. Install PowerShell using the MSI.
  2. Run the WinUtil upgrade command or script directly.
  3. Verify that the latest version is installed without the winget error.
  4. Confirm that the temporary MSI file is removed.

Documentation update

Add a README/INSTALL note:

If PowerShell was installed with the MSI, WinUtil automatically upgrades it via the official MSI installer instead of using winget upgrade.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions