From 2331c1b26e466552a02e914130472e8e989d1c27 Mon Sep 17 00:00:00 2001 From: Dmitry Nefedov Date: Sat, 8 Jun 2024 16:01:07 +0300 Subject: [PATCH] Improved UninstallPCHealthCheck function for Windows 10 --- .../Module/Sophia.psm1 | 18 +++++++++++------- .../Module/Sophia.psm1 | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index 2bd4a0a4..7138a9ee 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -10219,14 +10219,18 @@ function UninstallPCHealthCheck foreach ($MSI in @(Get-ChildItem -Path "$env:SystemRoot\Installer" -Filter *.msi -File -Force)) { $Name = $Files.Keys | Where-Object -FilterScript {$_ -eq $MSI.Name} - $File = $Files[$Name] - - # https://learn.microsoft.com/en-us/previous-versions/tn-archive/ee176615(v=technet.10) - # "22" is the "Subject" file property - if ($Folder.GetDetailsOf($File, 22) -eq "Windows PC Health Check") + # Check if necessary files exist in folder unless we get a bunch of errors for $File variable + if ($Name) { - Start-Process -FilePath msiexec.exe -ArgumentList "/uninstall $($MSI.FullName) /quiet /norestart" -Wait - break + $File = $Files[$Name] + + # https://learn.microsoft.com/en-us/previous-versions/tn-archive/ee176615(v=technet.10) + # "22" is the "Subject" file property + if ($Folder.GetDetailsOf($File, 22) -eq "Windows PC Health Check") + { + Start-Process -FilePath msiexec.exe -ArgumentList "/uninstall $($MSI.FullName) /quiet /norestart" -Wait + break + } } } diff --git a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 index 340a8b18..ba23230a 100644 --- a/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10_PowerShell_7/Module/Sophia.psm1 @@ -10225,14 +10225,18 @@ function UninstallPCHealthCheck foreach ($MSI in @(Get-ChildItem -Path "$env:SystemRoot\Installer" -Filter *.msi -File -Force)) { $Name = $Files.Keys | Where-Object -FilterScript {$_ -eq $MSI.Name} - $File = $Files[$Name] - - # https://learn.microsoft.com/en-us/previous-versions/tn-archive/ee176615(v=technet.10) - # "22" is the "Subject" file property - if ($Folder.GetDetailsOf($File, 22) -eq "Windows PC Health Check") + # Check if necessary files exist in folder unless we get a bunch of errors for $File variable + if ($Name) { - Start-Process -FilePath msiexec.exe -ArgumentList "/uninstall $($MSI.FullName) /quiet /norestart" -Wait - break + $File = $Files[$Name] + + # https://learn.microsoft.com/en-us/previous-versions/tn-archive/ee176615(v=technet.10) + # "22" is the "Subject" file property + if ($Folder.GetDetailsOf($File, 22) -eq "Windows PC Health Check") + { + Start-Process -FilePath msiexec.exe -ArgumentList "/uninstall $($MSI.FullName) /quiet /norestart" -Wait + break + } } }