Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get latest binary version from Archieve using Powershell

I need a PowerShell script to get latest binary version from this archive list https://download.docker.com/win/static/stable/x86_64/

So as when I run the script, it checks for latest zip and returns me latest version number and link to download. For example, if latest file is docker-24.0.6.zip then I need

  • 24.0.6
  • link to that zip which ultimately I can use to download

I have subsequent script to utilize that zip but I have never tried getting it from an archive url.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

docker-check.ps1:

$archiveUrl = "https://download.docker.com/win/static/stable/x86_64/"

$response = Invoke-WebRequest -Uri $archiveUrl

$pattern = '<a href="([^"]*docker-([\d.]+)\.zip)"'
$matches = [regex]::Matches($response.Content, $pattern)

$latestVersion = $null
$latestDownloadLink = $null

foreach ($match in $matches) {
    $downloadLink = $match.Groups[1].Value
    $version = $match.Groups[2].Value

    if ($latestVersion -eq $null -or [Version]$version -gt [Version]$latestVersion) {
        $latestVersion = $version
        $latestDownloadLink = $downloadLink
    }
}

if ($latestVersion -ne $null -and $latestDownloadLink -ne $null) {
    Write-Host "Latest Version: $latestVersion"
    Write-Host "Download Link: $archiveUrl$latestDownloadLink"
} else {
    Write-Host "Unable to find the latest version and download link."
}

Output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading