From d090e013db82d5513fbdf82d8bd3e5e47fd39bed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alan=20P=C5=82=C3=B3cieniak?= Date: Sat, 17 Dec 2022 17:01:59 +0100 Subject: [PATCH] Improved UninstallPCHealthCheck function performance --- src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 | 5 ++++- .../Module/Sophia.psm1 | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 index db1b7228..2ea18fb4 100644 --- a/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 +++ b/src/Sophia_Script_for_Windows_10/Module/Sophia.psm1 @@ -9020,10 +9020,13 @@ public static void Refresh() function UninstallPCHealthCheck { $Folder = (New-Object -ComObject Shell.Application).NameSpace("$env:SystemRoot\Installer") + $Files = [hashtable]::new() + $Folder.Items() | ForEach-Object -Process { $Files.Add($_.Name, $_) } | Out-Null # Find the necessary .msi with the Subject property equal to "Windows PC Health Check" foreach ($MSI in @(Get-ChildItem -Path "$env:SystemRoot\Installer" -Filter *.msi -File -Force)) { - $File = $Folder.Items() | Where-Object -FilterScript {$_.Name -eq $MSI.Name} + $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 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 d1e6aae8..57f5cda3 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 @@ -9028,10 +9028,13 @@ public static void Refresh() function UninstallPCHealthCheck { $Folder = (New-Object -ComObject Shell.Application).NameSpace("$env:SystemRoot\Installer") + $Files = [hashtable]::new() + $Folder.Items() | ForEach-Object -Process { $Files.Add($_.Name, $_) } | Out-Null # Find the necessary .msi with the Subject property equal to "Windows PC Health Check" foreach ($MSI in @(Get-ChildItem -Path "$env:SystemRoot\Installer" -Filter *.msi -File -Force)) { - $File = $Folder.Items() | Where-Object -FilterScript {$_.Name -eq $MSI.Name} + $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