powershell download file from delayed Link

I'm trying to download a msi Package from a Page which does a redirection in the background which downloads the file I want.

This is the Page I want to download the msi from: https://remotedesktopmanager.com/de/home/thankyou/rdmmsi

I tried several PowerShell Scripts, but none of them extracted the right download URL or downloaded the file. With Invoke-Webrequest -Outfile C:xxx only the HTML is saved.


the page uses javascript with a timeout to redirect to the current setup file. that's why you cannot use Invoke-WebRequest as this uses the Internet Explorer engine under the hood which also performs this javascript window.location redirect (resulting in opening the url in the default browser).

To only get the raw HTML you have to use Invoke-RestMethod

$website = Invoke-RestMethod -Uri 'https://remotedesktopmanager.com/de/home/thankyou/rdmmsi'

The full website is now stored in the variable $website without interpreting the javascript. To find the line with the string window.location i use Select-String which requires a file to be parsed. Thus the content of the variable is first stored in the file which is then parsed.

$tmpFilePath = 'C:\tmp\t.txt'
Out-File -FilePath $tmpFilePath -InputObject $website
$urlRedirectLine = Select-String -Path $tmpFilePath -SimpleMatch "window.location"
Remove-Item -Path $tmpFilePath

The new variable $urlRedirectLine (which content now is C:\tmp\t.txt:999: setTimeout(function () { window.location = 'https://cdn.devolutions.net/download/Setup.RemoteDesktopManager.2021.1.25.0.msi'; }, 4500);) contains the string we are looking for.

To extract that url i convert to variable to string and then use SubString() to extract the url itself. For this i look for the first ' and last ' in that variable.

$urlString = $urlRedirectLine.ToString()
$url = $urlString.Substring($urlString.IndexOf("'")+1,$urlString.LastIndexOf("'")-$urlString.IndexOf("'")-1)

Resulting in $url having the url https://cdn.devolutions.net/download/Setup.RemoteDesktopManager.2021.1.25.0.msi

To download the file you can again use Invoke-RestMethod

Invoke-RestMethod -Uri $url -OutFile 'C:\tmp\rdm.msi'