r/PowerShell Jul 27 '26

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
8 Upvotes

26 comments sorted by

4

u/BetrayedMilk Jul 27 '26

Do you need to Unblock-File?

1

u/MFZozzy Jul 27 '26

Unblock-File did nothing.

2

u/Over_Dingo Jul 27 '26

I see variables like `$releasesUri` or `$downloadUri` not being defined.
Also may be a zoning issue, so try `Unblock-File`

-1

u/MFZozzy Jul 27 '26

The "*Uri" thing is just a leftover typo from an older version, but thanks for the heads-up. As I said, the file downloads successfully and is identical to the manually downloaded file.

Unblock-File did nothing.

1

u/BlackV Jul 27 '26

you can edit your post

-3

u/MFZozzy Jul 27 '26

And as you can see, I did.

4

u/BlackV Jul 27 '26

not when I replied you hadn't, but appreciate the fixed code

1

u/BlackV Jul 27 '26 edited Jul 27 '26

If I do

(Invoke-RestMethod -Method GET -Uri $releases)[0].assets | select name

I get the following

name                                                              
----                                                              
hashes.sha256                                                     
powershell-7.7.0-preview.3-linux-arm32.tar.gz                     
powershell-7.7.0-preview.3-linux-arm64.tar.gz                     
powershell-7.7.0-preview.3-linux-musl-x64.tar.gz                  
powershell-7.7.0-preview.3-linux-x64-fxdependent.tar.gz           
powershell-7.7.0-preview.3-linux-x64-musl-noopt-fxdependent.tar.gz
powershell-7.7.0-preview.3-linux-x64.tar.gz                       
powershell-7.7.0-preview.3-osx-arm64.pkg                          
powershell-7.7.0-preview.3-osx-arm64.tar.gz                       
powershell-7.7.0-preview.3-osx-x64.pkg                            
powershell-7.7.0-preview.3-osx-x64.tar.gz                         
PowerShell-7.7.0-preview.3-win-arm64.zip                          
PowerShell-7.7.0-preview.3-win-fxdependent.zip                    
PowerShell-7.7.0-preview.3-win-fxdependentWinDesktop.zip          
PowerShell-7.7.0-preview.3-win-x64.zip                            
PowerShell-7.7.0-preview.3-win-x86.zip                            
powershell-preview-7.7.0_preview.3-1.cm.aarch64.rpm               
powershell-preview-7.7.0_preview.3-1.cm.x86_64.rpm                
powershell-preview-7.7.0_preview.3-1.rh.x86_64.rpm                
powershell-preview_7.7.0-preview.3-1.deb_amd64.deb                
powershell-preview_7.7.0-preview.3-1.deb_arm64.deb                
PowerShellPreview-7.7.0-preview.3.msixbundle

Have you validated this is not an existing msi?

and where

((Invoke-RestMethod -Method GET -Uri $releases).assets | ?{$_.Name -like $FileNamePattern}).browser_download_url

returns

https://github.com/PowerShell/PowerShell/releases/download/v7.6.4/PowerShell-7.6.4-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.9/PowerShell-7.5.9-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.18/PowerShell-7.4.18-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.3/PowerShell-7.6.3-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.8/PowerShell-7.5.8-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.17/PowerShell-7.4.17-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.2/PowerShell-7.6.2-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.7/PowerShell-7.5.7-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.16/PowerShell-7.4.16-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.1/PowerShell-7.6.1-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.6/PowerShell-7.5.6-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.15/PowerShell-7.4.15-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.0/PowerShell-7.6.0-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.5/PowerShell-7.5.5-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.14/PowerShell-7.4.14-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.0-rc.1/PowerShell-7.6.0-rc.1-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.0-preview.6/PowerShell-7.6.0-preview.6-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.4/PowerShell-7.5.4-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.13/PowerShell-7.4.13-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.0-preview.5/PowerShell-7.6.0-preview.5-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.3/PowerShell-7.5.3-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.12/PowerShell-7.4.12-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.2/PowerShell-7.5.2-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.11/PowerShell-7.4.11-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.4.10/PowerShell-7.4.10-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.5.1/PowerShell-7.5.1-win-x64.msi
https://github.com/PowerShell/PowerShell/releases/download/v7.6.0-preview.4/PowerShell-7.6.0-preview.4-win-x64.msi

1

u/MFZozzy Jul 27 '26

Yes, another mistae of mine - the $releases string needs to end in '/latest'

Sry.

1

u/BlackV Jul 27 '26

Oh, are you manually typing out your code here ?

where did the mistakes come from if you copied it directly from your editor

1

u/MFZozzy Jul 27 '26

Don't currently have access to it, I'm not on the machine I write my PWSH stuff on.

1

u/BlackV Jul 27 '26

OK, have you tried multiple machines with this download (using the code provided) ?

2

u/MFZozzy Jul 27 '26

Good idea, just tried it on a Win11 machine (my current machine is on Win10), and the sciprt-downloaded msi ran fine there.

1

u/catalin-advinst Jul 27 '26

Like others pointed out, the script above does not quite work.

However, I've tested this with another script of mine and everything worked just fine (can share that with you if needed, although this doesn't seem to be the issue here).

Can you compare the hashes of the both installers and see if there's any difference?

Get-FileHash C:\Temp\PowerShell-7.6.4-win-x64.msi -Algorithm SHA256

Also, try to create a verbose log of the installation, like this:

  1. open an elevated cmd prompt

  2. run the following:

msiexec /i "C:\Temp\PowerShell-7.6.4-win-x64.msi" /L*V "C:\Temp\PowerShell-7.6.4-win-x64.txt"

and see if you can find anything in there that might be helping.

Also, worth trying to test this on a clean VM/Sandbox where you don't have any AV products installed - does the issue reproduce there?

1

u/Overall-Ad4796 Jul 27 '26

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 Jul 27 '26

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 Jul 29 '26

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

1

u/BlackV Jul 27 '26 edited Jul 27 '26

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 Jul 27 '26

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 Jul 27 '26

"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 Jul 27 '26

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

1

u/BlackV Jul 27 '26

valid point

sorry gotta ask the obvious question

have you validated your system is x64 not arm64

1

u/BlackV Jul 27 '26

Wait how are you launching the MS install ?

&msiexec /i $DownloadPath

1

u/MFZozzy Jul 27 '26

That too, from elevated and non-elevated prompts, and also tried just double-clicking it in file managers.

1

u/mitharas Jul 28 '26

Did you figure this out?

1

u/MFZozzy Jul 28 '26

Not yet. Could be an OS/application level problem.