Azure / Azure/AVDSessionHostReplacer

Improvement for supporting images where the image version is not recognized

Open
#23 2 comments 0 reactions 1 assignee Claimed by @WillyMoselhy View on GitHub
bug
Dominant language
PowerShell
Stars
49
Forks
34
PR merge metrics
No merged PRs in 30d

Description

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+\.(?\d{2})(?\d{2})(?\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 "^(?\d{2}|\d{4})\.(?\d{2})\.(?\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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.