I am having am trying to write a script to get the latest version of citrix receiver by scraping the website with PowerShell. I am to a point where I have the latest versions, but I can't sort them descending correctly because the version minor is prioritizing 9-1 over 99-10.
Here is my code
$url = "https://www.citrix.com/downloads/citrix-receiver/"
$html = Invoke-WebRequest -Uri "$url"
$versionLinks = $html.Links | where innerHTML -Match "Receiver \d+(\.\d+)+.* for Windows$" | Sort-Object -Property innerHTML -Descending
$versionArray = @()
foreach ($version in $versionLinks){
[version]$VersionNumber = $version.innerHTML -split " " | Select -First 2 | select -Last 1
$versionArray += $VersionNumber
}
$versionArray = Sort-Object -InputObject $versionArray -Descending -Property minor
$LatestAppVersion = $versionArray[0]
$LatestAppVersion
What it outputs is 4.9. $versionArray looks like
Major Minor Build Revision
----- ----- ----- --------
4 9 -1 -1
4 8 -1 -1
4 7 -1 -1
4 6 -1 -1
4 5 -1 -1
4 3 100 -1
4 12 -1 -1
4 11 -1 -1
4 10 1 -1
I would like it to be
Major Minor Build Revision
----- ----- ----- --------
4 12 -1 -1
4 11 -1 -1
4 10 1 -1
4 9 -1 -1
4 8 -1 -1
4 7 -1 -1
4 6 -1 -1
4 5 -1 -1
4 3 100 -1
This question is similar to mine. I am using sorting version though so I am not sure why I am getting a different result. I did try using [System.Version] in case [version] was not specific enough.