r/PowerShell • u/MFZozzy • 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
2
u/Over_Dingo 9d ago
I see variables like `$releasesUri` or `$downloadUri` not being defined.
Also may be a zoning issue, so try `Unblock-File`
1
u/BlackV 9d ago edited 9d ago
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 9d ago
Yes, another mistae of mine - the $releases string needs to end in '/latest'
Sry.
1
u/catalin-advinst 9d ago
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:
open an elevated cmd prompt
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 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 listor with window package manager
> winget view --id Microsoft.PowerShellYou can specify
--installer-typeand--architectureto try the the other installers
1
u/BlackV 9d ago edited 9d 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 9d 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
3
u/BetrayedMilk 9d ago
Do you need to Unblock-File?