As a system admin or as an application packager we have various scenarios
where we need to get the details of installed applications. We come across situations where we need to include logic in our
scripts to check if certain application or a product code exists on the
machine or not.
There are various ways to check this, PowerShell
queries are one of those. In PowerShell, we can either use WMI Class to get
the details or query the windows registry to get the required details.Below
are few commands which can be used to get the details of the applications
installed on the machine. These PowerShell one-liners can be used directly or
along with the conditional statements like “IF”.
Querying WMI Class
Get details of all the applications installed on the machine:
Get-WmiObject Win32_Product
Get the names of products installed:
(Get-WmiObject Win32_Product).Name
Get the Product Codes and Names of all applications installed:
Get-WmiObject Win32_Product | Format-Table Name, IdentifyingNumber
Get the name of the application when product code is known:
(Get-WmiObject Win32_Product | Where {$_.IdentifyingNumber –eq '<ProductCodeHere>'}).Name
Get the product code of the application when product name is
known:
(Get-WmiObject Win32_Product | Where {$_.Name –eq '<ProductNameHere>'}).IdentifyingNumber
Querying Windows Registry
The WMI method of using Win32_Product class to retrieve the data can be slow, querying the windows registry is another alternative.
Note: While using the below codes on a 64-bit system, one has to be
sure if the application registry exists under 32-bit or 64-bit registry
hive.
For checking 32-bit registry on a 64-bit machine, replace:
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
with
HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
Get details of all the applications installed:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher | Format-Table –AutoSize
Get the names of all the products installed:
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName | Format-Table –AutoSize
Get the name of the application when product code is known:
(Get-ItemProperty 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\<ProductCode>').DisplayName
Get the product code of the application when product name is known:
(Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | Where {$_.DisplayName -eq '<ProductName>'}).PSChildName
Disclaimer - Test and Use the above scripts/snippets with caution. The author does not hold any responsibility for any problem caused. This is issued for experimental purpose only.