Downloading Files - WIldcard

Afternoon.

Hopefully a very quick question,

I would like to download a .msi file from in this instance blender.org. The full path to the MSI contains the Version of blender… blender-3-4-1.msi, Is there a way I could parse from an html page for the msi file but wildcard the 3-4-1, as this would change often. Its only to keep the msi file up to date

pr0xibus,
Welcome to the forum. :wave:t3:

In general something like this is possible but it would be the best option if you have an API you can trigger.

Well URIs are specific and while you can’t wildcard search for URIs the Invoke-WebRequest will return all seen links in the Property Links.href, so you can wild card search those for the proper URI for the msi file and then call Invoke-WebRequest again with it and -OutFile to save the MSI.

For Blender specifically you can query https://www/blender.org/download/, then look for blender.msi* which gives you the latest blender download URI. Then query that and again look at links for blender.msi and you will have your binary to download

1 Like

Much appreicated for the replies folks. Almost there,

Excuse the long winded way of doing this, I will tidy it up later on.

$blender_site = Invoke-WebRequest -Uri "https://www.blender.org/download/"
            $blender_links = $blender_site.Links.href | Where-Object{$_ -like "*.msi*"} | select -First 1
            $blender_out = Out-String -InputObject $blender_links
            Invoke-WebRequest -Uri $blender_out -OutFile $pwd\blender.msi

The problem I have is the link is a redirect so although it is listed as Link1 this actually redirects to Link2 or any available mirror

What is the best way to FOLLOW the redirected link

I think a website have different manner to redirect to a new link.
Here, if you see the return of your second Invoke-Webrequest, there is a refresh header with the link.

Below a quick and dirty proposition.

$blender_site = Invoke-WebRequest -Uri "https://www.blender.org/download/"
$blender_links = $blender_site.Links.href | Where-Object{$_ -like "*.msi*"} | select -First 1
$blender_out = Out-String -InputObject $blender_links
$a = Invoke-WebRequest -Uri $blender_out 
$b = $a.Headers.refresh -split ";"
$c = $b -split "url="
Invoke-WebRequest -Uri $c[2] -OutFile $pwd\blender.msi
```