PowerShell Win32_Product

PowerShell Script to Display Installed Programs

Let us ask PowerShell the question, which programs are installed on this machine?  I’ll bet you will find at least one program that has muscled its way into your computer without your approval.

Topics for PowerShell’s Win32_Product

 ♣

Introduction

I would like to remind you that most PowerShell scripts merely mimic tasks that you can perform manually.  Another prime reason for scripting is to automate boring tasks.  In the case of this week’s script it would be tedious to wade through all the programs in the C: \Programs Files.  There again, other files maybe stored in the C: \Programs Files (x86) folder, while yet more programs maybe stored who knows where.  For this particular task we can also use WMIC to display a list of installed programs.

Mission: To List Your Installed Programs

Our real-life task is to identify rogue programs that have persuaded you (or another user) to install them.  To achieve our mission we are going to use PowerShell.  Specifically, employ a WMI class called Win32_Product.

Barking Eddie’s Non-PowerShell Solution

Here is Eddie’s short but sweet WMI method for listing all programs installed on a computer.  Go to the command prompt, and type:

# Note from the command-line type:
WMIC
Product get name

Note: You could type the above command in PowerShell, however I wanted to emphasise that WMIC an operating system command.

PowerShell Win32_Product Equivalent to WMIC’s List Installed Programs

In the following example we build upon the above WMI idea by researching Get-WmiObject’s classes.  The most useful of which is Win32_Product.

Eddie’s tried and trusted method of using WMIC is good.  Yet PowerShell can not only match this command-line program, but also it has features such as Sort-Object and -groupBy that Eddie cannot reproduce in WMIC.

# PowerShell Win32_Product script to list installed programs
Clear-Host
Get-WmiObject Win32_Product | Sort-Object Name | `
Format-Table Name, Version, Vendor

Optional parameter -groupBy

# Win32_Product with -groupBy
Get-WmiObject Win32_Product | Sort-Object Vendor, Name `
 | Format-Table Vendor, Name, Version -groupBy Vendor

Note:  While it does not change the output, you could explicitly define the WMI Class thus:
Get-WmiObject -class "Win32_Product"

Guy Recommends: Free WMI Monitor for PowerShellSolarwinds Free WMI Monitor for PowerShell

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

Dissecting Win32_Product and Returning to Basics

You could scale back this script to the simple line: Get-WmiObject Win32_Product.  Then append | Get-Member and from there, develop your own tactics for interrogating the extra properties available to Win32_Products.  For example, append the properties, HelpLink, HelpTelephone to your basic script.

Fools’ Gold Uninstall Registry Setting.  Close but no cigar!

Here is a script which ingeniously reminds us of how to interrogate the registry, but for our mission it has a fatal flaw.  The problem is that this method displays only well behaved programs that have an uninstall setting in the registry.

# PowerShell script to display programs from registry.
Clear-Host
$i=0
$RegLoc = Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall
$Programs = $RegLoc | foreach {Get-ItemProperty $_.PsPath}

Foreach ($name in $Programs | Sort-Object DisplayName) `
{Write-Host $name.Displayname; $i++
}

Write-host "There are $i programs installed"

Summary of PowerShell Win32_Product

Here we asked PowerShell to list which programs are installed on your computer.  I’ll bet you will find at least one rogue program that has found its way into your computer without your permission.

If you like this page then please share it with your friends

 


See More Microsoft PowerShell WMI Examples:

Home   • PowerShell Get-WmiObject   • Win32_ComputerSystem   • Free WMI Monitor

WMI Class  • [WMI] Type  • Win32_printer   • Win32_product   • SystemRestore   • WMI Services

WMI Disk   • DNS   • Memory  • PowerShell -Filter   • Check Server UpTime   • ConvertToDateTime

Please email me if you have a script examples. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.