Search for Details on Installed Software with Powershell
Anyone that has ever queried for installed software knows that win32_Product is annoyingly slow. There are plenty of solutions out there to pull in all installed software, then filter, then act but I wanted something lightweight and could drill down to my target in a single function. The script below doesn’t validate that targetAttribute name is legit in the registry but can be used to query for any attribute matches you may be targeting.
# Copyright (c) 2017 infiniteloop.io # http://infiniteloop.io # Version 1.0 - 2017-10-07 # # Redistribution and use in source and binary forms, with or without modification, are permitted # provided that the following conditions are met: # 1) Redistributions of source code must retain the above copyright notice, this list of conditions # and the following disclaimer. # 2) Redistributions in binary form must reproduce the above copyright notice, this list of # conditions and the following disclaimer in the documentation and/or other materials provided # with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <# .Synopsis Function to search Windows registry for information about installed software using multiple attributes .DESCRIPTION Software installed on Windows clients will generally store product information (version, name, uninstlal string) in the registry. This function can be used to search against multiple attributes and compare against known values. The default mode matches targetData exactly. The fuzzy switch enables a like operator to be used with wildcard searches. .EXAMPLE . C:\Find-SoftwareRegistryInfo.ps1 -targetAttributeName 'DisplayName' -targetData 'Sketchup*' -fuzzy .EXAMPLE . C:\Find-SoftwareRegistryInfo.ps1 -targetAttributeName 'Publisher' -targetData 'Microsoft Corporation' .EXAMPLE . C:\Find-SoftwareRegistryInfo.ps1 -targetAttributeName 'DisplayName' -targetData '*Office Professional Plus*' -fuzzy .EXAMPLE . C:\Find-SoftwareRegistryInfo.ps1 -targetAttributeName 'DisplayName' -targetData '*Office Professional Plus*' -fuzzy | ? {$_.uninstallstring -notmatch '^msi'} #> [CmdletBinding()] Param ( [Parameter(Mandatory=$true,Position=0)] $targetAttributeName, [Parameter(Mandatory=$true,Position=1)] $targetData, [Parameter(Mandatory=$false)] [switch]$fuzzy ) $regPathArr = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall') if($fuzzy) { Write-Debug "$($MyInvocation.MyCommand.name):`tFuzzy search: $targetAttributeName ~ $targetData" $regPathArr | % {gci $_ -ea 0 | % {$keyInfo = Get-ItemProperty $_.PSPath; if($keyInfo.$targetAttributeName -like "$targetData"){$keyInfo}}} } else { Write-Debug "$($MyInvocation.MyCommand.name):`tStandard search: $targetAttributeName = $targetData" $regPathArr | % {gci $_ -ea 0 | % {$keyInfo = Get-ItemProperty $_.PSPath; if($keyInfo.$targetAttributeName -eq $targetData){$keyInfo}}} }
Quick comparison searching for Sketchup using win32_product and this script: