Mike Meyer
03/18/2025, 10:12 PMMike Meyer
03/18/2025, 11:54 PMJeremy Saunders
03/19/2025, 12:29 AMJeremy Saunders
03/19/2025, 12:34 AM# This function has been written to clear out references to previously installed products
# that may cause an issue for the package cache during installation.
Function Delete-CachedProducts {
param ([string]$Product)
$CompressedGuids = ""
$ErrorActionPreference = "stop"
Try {
$CompressedGuids = Get-ChildItem -Path HKCU:\Software\Microsoft\Installer\Products | Select-Object -ExpandProperty PSChildName
}
Catch {
#
}
$ErrorActionPreference = "Continue"
if (!([String]::IsNullOrEmpty($CompressedGuids))) {
ForEach ($CompressedGuid in $CompressedGuids) {
$ErrorActionPreference = "stop"
try {
If ((Get-ItemProperty -Path "HKCU:\Software\Microsoft\Installer\Products\$CompressedGuid" | Select-Object -ExpandProperty "ProductName") -Like "*$Product*") {
write-verbose "Deleting" -verbose
Remove-Item -Path "HKCU:\Software\Microsoft\Installer\Products\$CompressedGuid" -Recurse -Force -Confirm:$false
}
}
catch {
#
}
$ErrorActionPreference = "Continue"
}
}
}
Examples:
Delete-CachedProducts -Product:"Trimble Solutions ImportSDK, IFC plugin"
Delete-CachedProducts -Product:"FARO LS"