Search code examples
powershellurlmatchinnerhtmlinvoke-webrequest

How I can get the download URL of the latest version of Cura from it's website with powersell?


I want to find download URL for the latest version of Cura right now it is (https://github.com/Ultimaker/Cura/releases/download/5.2.1/Ultimaker-Cura-5.2.1-win64.exe) and I have written (Invoke-WebRequest -Uri "https://ultimaker.com/software/ultimaker-cura").innerHTML -match "(https*.exe)" I tried it with .innerHTML or usebasicparsing or Invoke-Restmethod and I could not find it, can someone help me to find it? thanks in advance


Solution

  • I would suggest you to use the release API from GitHub to find out the latest release of the software.

    $response = Invoke-RestMethod -Uri "https://api.github.com/repos/Ultimaker/Cura/releases/latest"
    $windowsRelease = $response.assets | Where-Object { $_.name -match "win64" }
    

    Please note that I am applying a Where-Object here to filter out only win64, because a release can contain binary for different platforms.

    Then you can use browser_download_url property to get the download url which you can use it along side with Invoke-WebRequest to download it

    # download the file
    Invoke-WebRequest $windowsRelease.browser_download_url -OutFile "CuraLatest.exe"