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
30 changes: 22 additions & 8 deletions scripts/Agent/Compare-InstallerSnapshots.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ function Diff-Sets {
return [pscustomobject]@{ Added = $added; Removed = $removed }
}

function Get-DisplayNameList {
# Tolerates $null, an unwrapped object, and the empty {} object Windows
# PowerShell emits for an empty list -- direct property access on those
# shapes throws under Set-StrictMode.
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 +106,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