Refactor: Simplify update package file lookup

Streamlines the logic for finding Cumulative Update (CU) and Cumulative Update Preview (CUP) files by removing redundant code.

The file search now relies directly on a wildcard search using the KB article ID, instead of first attempting a match with a specific filename. This change simplifies the script and makes the discovery process more direct. Also removes commented-out code.
This commit is contained in:
rbalsleyMSFT
2025-07-21 11:24:44 -07:00
parent 721f93d82d
commit ba1dd3df6b
-15
View File
@@ -2093,7 +2093,6 @@ function Get-UpdateFileInfo {
$links = Get-KBLink -Name $kb $links = Get-KBLink -Name $kb
foreach ($link in $links) { foreach ($link in $links) {
$fileName = ($link -split '/')[-1] $fileName = ($link -split '/')[-1]
# $url = $link
$architectureMatch = $false $architectureMatch = $false
if ($link -match 'x64' -or $link -match 'amd64') { if ($link -match 'x64' -or $link -match 'amd64') {
@@ -4683,28 +4682,14 @@ try {
WriteLog "Latest SSU identified as $SSUFilePath" WriteLog "Latest SSU identified as $SSUFilePath"
} }
if ($cuUpdateInfos.Count -gt 0) { if ($cuUpdateInfos.Count -gt 0) {
# Use the actual downloaded file name from the update info
$CUFileName = $cuUpdateInfos[0].Name
$CUPath = (Get-ChildItem -Path $KBPath -Filter $CUFileName -Recurse).FullName
if (-not $CUPath) { if (-not $CUPath) {
# If exact match fails, try to find by KB article ID
$CUPath = (Get-ChildItem -Path $KBPath -Filter "*$cuKbArticleId*" -Recurse | Select-Object -First 1).FullName $CUPath = (Get-ChildItem -Path $KBPath -Filter "*$cuKbArticleId*" -Recurse | Select-Object -First 1).FullName
if ($CUPath) {
$CUFileName = Split-Path $CUPath -Leaf
}
} }
WriteLog "Latest CU identified as $CUPath" WriteLog "Latest CU identified as $CUPath"
} }
if ($cupUpdateInfos.Count -gt 0) { if ($cupUpdateInfos.Count -gt 0) {
# Use the actual downloaded file name from the update info
$CUPFileName = $cupUpdateInfos[0].Name
$CUPPath = (Get-ChildItem -Path $KBPath -Filter $CUPFileName -Recurse).FullName
if (-not $CUPPath) { if (-not $CUPPath) {
# If exact match fails, try to find by KB article ID
$CUPPath = (Get-ChildItem -Path $KBPath -Filter "*$cupKbArticleId*" -Recurse | Select-Object -First 1).FullName $CUPPath = (Get-ChildItem -Path $KBPath -Filter "*$cupKbArticleId*" -Recurse | Select-Object -First 1).FullName
if ($CUPPath) {
$CUPFileName = Split-Path $CUPPath -Leaf
}
} }
WriteLog "Latest Preview CU identified as $CUPPath" WriteLog "Latest Preview CU identified as $CUPPath"
} }