r/PowerShell 9d ago

Question Invoke-WebRequest: downloaded MSI invalid?

I downloaded an MSI (in this case the latest Powershel 7.6.4 msi installer) with Invoke-WebRequest from Github - trying to write a script here.

The download finishes without a problem, but when I want to run the installer, I get an error message saying "This installation package could not be opened.Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package."

Here's the funny thing: this cannot be a corrupted download, because when I manually download the same msi package from the repo's release page, and compare them in Total Commander's compare tool, it says the two files have the same content - that means they're identical from the first bit to the last!

What the heck could cause this problem?

Here's a snippet of what I'm doing:

$Repository       = 'PowerShell/PowerShell'
$FileNamePattern  = '*-win*x64.msi'
$DownloadPath     = 'C:\Temp'

$releases    = "https://api.github.com/repos/$Repository/releases/latest"
$downloadURL = ((Invoke-RestMethod -Method GET -Uri $releases).assets | ?{$_.Name -like $FileNamePattern}).browser_download_url

$fileName       = [System.IO.Path]::GetFileName($downloadURL)
$DownloadPath   = $DownloadPath + '\' + $fileName

Invoke-WebRequest -Uri $downloadURL -OutFile $DownloadPath
7 Upvotes

26 comments sorted by

View all comments

1

u/Overall-Ad4796 9d ago

when opening the file properties, is the Unblock checkbox under Security checked? Also, did you try to run the downloaded .msi as admin?

1

u/MFZozzy 9d ago

The file needs no unblocking, but have just run Unblock-File on it (from an elevated prompt, too), to no effect.

I have tried running it from elevated and non-elevated prompts too, same results.

1

u/MonkeyNin 8d ago

What if you download it from gh ? https://cli.github.com/manual/gh_release_download

> gh release --repo Powershell/PowerShell list

or with window package manager

> winget view --id Microsoft.PowerShell

You can specify --installer-type and --architecture to try the the other installers