Azure / AVDSessionHostReplacer

MIT License
35 stars 22 forks source link

Improvement for supporting images where the image version is not recognized #23

Open buysoft opened 2 months ago

buysoft commented 2 months ago

Hi,

Today I discovered that using this image:

    "visStudio_2022_Pro_win11-m365-gen2": {
        "publisher": "microsoftvisualstudio",
        "offer": "visualstudioplustools",
        "sku": "vs-2022-pro-general-win11-m365-gen2",
        "version": "latest"
    }

Results in a date format not recognized by the Get-SHRLatestImageVersion.ps1. This is because the RegEx expects a year format of 24 instead of 2024. But the Image Version provided above results in 2024, resulting in an error when running the Function App.

So I changed this code:

if ($azImageVersion -match "\d+\.\d+\.(?<Year>\d{2})(?<Month>\d{2})(?<Day>\d{2})") {
    $azImageDate = Get-Date -Date ("20{0}-{1}-{2}" -f $Matches.Year, $Matches.Month, $Matches.Day)
    Write-PSFMessage -Level Host -Message "Image date is {0}" -StringValues $azImageDate
}
else {
    throw "Image version does not match expected format. Could not extract image date."
}

With this code:

if ($azImageVersion -match "^(?<Year>\d{2}|\d{4})\.(?<Month>\d{2})\.(?<Day>\d{2})$") {
    if ($Matches.Year.Length -eq 2) {
        $year = (Get-Date -Format "yyyy").Substring(0,2) + $Matches.Year
    } else {
        $year = $Matches.Year
    }
    $azImageDate = Get-Date -Date ("{0}-{1}-{2}" -f $year, $Matches.Month, $Matches.Day)
    Write-PSFMessage -Level Host -Message "Image date is {0}" -StringValues $azImageDate
} else {
    throw "Image version does not match expected format. Could not extract image date."
}

Perhaps you can use it in this project or provide me with feedback to even solve this in a better way?

WillyMoselhy commented 2 months ago

Hey great find! I will review the rest of the images and try to include this in the next release. Stay tuned for the beta 🐣

buysoft commented 2 months ago

Thanks, and thanks for having this project! Enjoying it!

I will stay tuned for the beta.