1

I'm working on a script to automate repair of software using msiexec. The issue I"m having is that when I call:

get-wmiobject -class win32_product -filter "name of software" | foreach-object {$_.IdentifyingNumber}

The time it takes to parse each product number is nearly 5-10 minutes. Is there a faster way of doing this?

  • 4
    yes! use the uninstall key in the registry. look up "win32_Product is evil` and you will see what registry stuff you need to check. [*grin*] – Lee_Dailey Apr 18 '19 at 17:44
  • [My answer here](https://stackoverflow.com/questions/71575378/powershell-for-software-inventory/71576041#71576041) explains why `Win32_Product` should be avoided, essentially it can and will eventually make an unplanned change or cause unexpected resource contention when enumerating the software inventory. – codewario Mar 24 '22 at 14:37

1 Answers1

0

As Lee_Dailey mentioned, you can get this information from the uninstall key in the registry.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

The following will get you the Name and GUID of applications installed with an entry in the uninstall key. The -match "^{.+}$" returns only entries that begin with { and end with }. If you want the GUID output without the braces {} then you can cast it to [GUID], e.g. [GUID][String]$matches.Values.

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
%{
    if(($_.Name | Split-Path -Leaf) -match "^{.+}$")
    {
        [PSCustomObject]@{
            GUID = [String]$matches.Values
            Name = [String]($_ | Get-ItemProperty -ErrorAction SilentlyContinue).DisplayName
        }
    }
}

Outputs:

GUID                                   Name                                                          
----                                   ----                                                          
{0CA4BB37-FF4A-42C6-A39C-11CB0BB8D395} Microsoft .NET Core Host - 2.1.8 (x64)                        
{1657ABEE-7D56-416A-B7E0-A89CC5AAD0F7} Microsoft Azure Compute Emulator - v2.9.6 
...
Jacob
  • 1,182
  • 12
  • 18