Skip to content

Commit 204b7d3

Browse files
committed
Guard MSI UpgradeCode lookup against missing registry key
Get-ADTApplication built its MSI UpgradeCode lookup table with an unguarded Get-ChildItem on HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes. On machines where that key does not exist (e.g. images with no MSI-registered upgrade codes), Get-ChildItem threw a PathNotFound error that aborted the function's begin block, breaking any caller such as Uninstall-ADTApplication. Add -ErrorAction Ignore to match the pattern already used for the uninstall key enumeration. When the key is absent the pipeline yields no items, the scriptblock's begin/end blocks still run, and the lookup table is simply empty; downstream indexing already returns $null for GUIDs that are not present. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XLNM98Nd3HZLTWFatRVgB1
1 parent dff8573 commit 204b7d3

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/PSAppDeployToolkit/Public/Get-ADTApplication.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function Get-ADTApplication
178178

179179
# Define compiled regex for use throughout main loop.
180180
$updatesAndHotFixesRegex = [System.Text.RegularExpressions.Regex]::new('((?i)kb\d+|(Cumulative|Security) Update|Hotfix)', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase -bor [System.Text.RegularExpressions.RegexOptions]::Compiled)
181-
$msiUpgradeCodeLookupTable = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes\* | Get-ItemProperty | & {
181+
$msiUpgradeCodeLookupTable = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes\* -ErrorAction Ignore | Get-ItemProperty | & {
182182
begin
183183
{
184184
# Open lookup table dictionary for returning at the end.

0 commit comments

Comments
 (0)