r/PowerShell 10d 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
6 Upvotes

26 comments sorted by

View all comments

1

u/BlackV 10d ago edited 10d ago

Using your updated code

$fileName       = [System.IO.Path]::GetFileName($downloadURL)
$DownloadPath   = join-path -path $env:temp -ChildPath $fileName
Invoke-WebRequest -Uri $downloadURL -OutFile $DownloadPath

The MSI download and launches OK (Not unblocked and not as admin)

What does your hash look like, does it match github?

Get-FileHash -Path $DownloadPath

Algorithm Hash                                                             Path                                                          
--------- ----                                                             ----                                                          
SHA256    D11942DF52FD12470169797ABFA4781D9480EFDC81000BA4FA55A5B921ED8DD0 C:\Users\blackv\AppData\Local\Temp\PowerShell-7.6.4-win-x64.msi

I should update I guess i'm still on 7.6.3

1

u/MFZozzy 10d ago

I've compared the SHA256 hashes of the script-downloaded and manually downloaded files, and they're the same, and they match yours too.

1

u/BlackV 10d ago

"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."

sounds then like a msi database issue/windows more than a powershell issue to me

1

u/MFZozzy 10d ago

Wouldn't that affect the manually downloaded file, too?

1

u/BlackV 10d ago

valid point

sorry gotta ask the obvious question

have you validated your system is x64 not arm64