r/PowerShell • u/MFZozzy • 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
4
u/BetrayedMilk Jul 27 '26
Do you need to Unblock-File?
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/BlackV Jul 27 '26 edited Jul 27 '26
If I do
I get the following
Have you validated this is not an existing msi?
and where
returns
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/BlackV Jul 27 '26 edited Jul 27 '26
Using your updated code
The MSI download and launches OK (Not unblocked and not as admin)
What does your hash look like, does it match github?
I should update I guess i'm still on 7.6.3
1
u/BlackV Jul 27 '26
Wait how are you launching the MS install ?
1
u/mitharas Jul 28 '26
Did you figure this out?
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:
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?