Update BuildFFUVM.ps1

- Update Get-LatestWindowsKB to support searching for Windows Server updates
- Improve the HTML regex to return a more precise match by using the $WindowsRelease variable for lookbehind based searching
This commit is contained in:
JonasKloseBW
2024-09-23 04:02:28 +02:00
committed by GitHub
parent 0b151f9054
commit 5acac4ba5b
+13 -4
View File
@@ -2414,16 +2414,21 @@ function Get-KBLink {
}
function Get-LatestWindowsKB {
param (
[ValidateSet(10, 11)]
[int]$WindowsRelease
[Parameter(Mandatory)]
[ValidateSet(10, 11, 2016, 2019, 2022, 2025)]
[int]$WindowsRelease,
[Parameter(Mandatory)]
[string]$WindowsVersion
)
# Define the URL of the update history page based on the Windows release
if ($WindowsRelease -eq 11) {
$updateHistoryUrl = 'https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information'
}
else {
elseif ($WindowsRelease -eq 10) {
$updateHistoryUrl = 'https://learn.microsoft.com/en-us/windows/release-health/release-information'
} else {
$updateHistoryUrl = 'https://learn.microsoft.com/en-us/windows/release-health/windows-server-release-info'
}
# Use Invoke-WebRequest to fetch the content of the page
@@ -2433,7 +2438,11 @@ function Get-LatestWindowsKB {
$VerbosePreference = $OriginalVerbosePreference
# Use a regular expression to find the KB article number
$kbArticleRegex = 'KB\d+'
if ($WindowsRelease -le 11) {
$kbArticleRegex = "(?:Version $WindowsRelease \(OS build d+\)(?!(KB)).)*?KB\d+"
} else {
$kbArticleRegex = "(?:Windows Server $WindowsRelease \(OS build d+\)(?!(KB)).)*?KB\d+"
}
$kbArticle = [regex]::Match($response.Content, $kbArticleRegex).Value
return $kbArticle