Better error handling in Windows PS1 installer (#33555)

**Related issue:** Resolves #33555 

Wrap Get-ItemProperty calls in try/catch blocks during registry
enumeration to gracefully handle terminating exceptions (e.g.
System.InvalidCastException) from malformed registry entries, logging
the offending path instead of aborting.
This commit is contained in:
Juan Fernandez
2026-04-02 12:50:20 -04:00
committed by GitHub
parent 3a12ba8571
commit 74ff57af8d
2 changed files with 5 additions and 2 deletions
@@ -0,0 +1 @@
* Wrapped Get-ItemProperty calls in try/catch blocks during registry enumeration to gracefully handle terminating exceptions (e.g. System.InvalidCastException) from malformed registry entries, logging the offending path instead of aborting.
+4 -2
View File
@@ -580,7 +580,8 @@ function Force-Remove-Orbit {
Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -Recurse -ErrorAction "SilentlyContinue" | Where-Object {($_.ValueCount -gt 0)} | ForEach-Object {
# Filter for osquery entries
$properties = Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction "SilentlyContinue" | Where-Object {($_.DisplayName -eq "Fleet osquery")}
$entryPath = $_.PSPath
$properties = try { Get-ItemProperty -LiteralPath $entryPath -ErrorAction "SilentlyContinue" | Where-Object {($_.DisplayName -eq "Fleet osquery")} } catch { Write-Host "Skipping invalid registry entry at ${entryPath}: $_"; $null }
if ($properties) {
#Remove Registry Entries
@@ -622,7 +623,8 @@ function Force-Remove-Osquery {
Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" -Recurse -ErrorAction "SilentlyContinue" | Where-Object {($_.ValueCount -gt 0)} | ForEach-Object {
# Filter for osquery entries
$properties = Get-ItemProperty -LiteralPath $_.PSPath -ErrorAction "SilentlyContinue" | Where-Object {($_.DisplayName -eq "osquery")}
$entryPath = $_.PSPath
$properties = try { Get-ItemProperty -LiteralPath $entryPath -ErrorAction "SilentlyContinue" | Where-Object {($_.DisplayName -eq "osquery")} } catch { Write-Host "Skipping invalid registry entry at ${entryPath}: $_"; $null }
if ($properties) {
#Remove files from osquery location