Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions scripts/Agent/Compare-InstallerSnapshots.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ function Diff-Sets {
return [pscustomobject]@{ Added = $added; Removed = $removed }
}

function Get-DisplayNameList {
# Safely extract DisplayName values from a snapshot's UninstallEntries.
# Robust to $null, to a single unwrapped object, and to the empty object ({})
# that ConvertTo-Json can emit for an empty list (Collect-InstallerSnapshot serializes
# an empty List as {} in Windows PowerShell). Under Set-StrictMode, blindly reading
# $entry.DisplayName on such an object throws PropertyNotFoundException.
param([Parameter(Mandatory = $false)]$Entries)

$names = New-Object System.Collections.Generic.List[string]
if ($null -eq $Entries) { return ,$names }

foreach ($entry in @($Entries)) {
if ($null -eq $entry) { continue }
$prop = $entry.PSObject.Properties['DisplayName']
if ($null -eq $prop) { continue }
$value = [string]$prop.Value
if (-not [string]::IsNullOrWhiteSpace($value)) { $names.Add($value) }
}

return ,$names
}

function ConvertTo-PropertyMap {
param([Parameter(Mandatory = $false)]$Value)

Expand Down Expand Up @@ -86,14 +108,8 @@ $reportLines.Add("After: $AfterSnapshotPath")
$reportLines.Add("")

# Uninstall entries
$beforeProducts = @()
foreach ($p in ($before.UninstallEntries | ForEach-Object { $_ })) {
$beforeProducts += ([string]$p.DisplayName)
}
$afterProducts = @()
foreach ($p in ($after.UninstallEntries | ForEach-Object { $_ })) {
$afterProducts += ([string]$p.DisplayName)
}
$beforeProducts = Get-DisplayNameList -Entries $before.UninstallEntries
$afterProducts = Get-DisplayNameList -Entries $after.UninstallEntries

$diffProducts = Diff-Sets -Before (To-StringSet -Items $beforeProducts) -After (To-StringSet -Items $afterProducts)
$reportLines.Add("Uninstall entries")
Expand Down
Loading