Ezine 195 – PowerShell Displays Your Installed Programs

Ezine 195 – PowerShell Displays Your 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


This Week’s Secret

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.

Confession: I have been a little slow to embrace social networking, however, this ezine is now available at  http://twitter.com/ComputerPerfGuy

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.

Pre-requisite – Get PowerShell 2.0 from Connect

  • PowerShell is built-in to Microsoft’s latest operating systems: Windows 7, Vista and Windows Server 2008.  In these cases all you need to do is navigate to the Control Panel, Programs, and ‘Turn Windows feature on’.
  • For older operating systems, such as XP and Windows Server 2003, you need to download and install PowerShell together with .Net Framework from Microsoft’s website.
  • PowerShell Version 2.0 RTM is now available for download.  You can check which version you have installed by typing $host at the PowerShell command line.  If you already have version 1 and wish to upgrade to V2, this can be a challenge, so even Guy had to read the instructions that Microsoft provide.  That said the following examples work perfectly well with PowerShell v1.0

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:
Product get name

Note: Following last week’s ezine you could type the above command in PowerShell, however I wanted to emphasise that WMIC an operating system command.

PowerShell 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.

In truth it’s not easy to improve upon Eddie’s tried and trusted method of using WMIC.  However, 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 script to list installed programs

Get-WmiObject Win32_Product |
Sort-Object Name |
Format-Table Name, Version, Vendor

Optional parameter -groupBy

Get-wmiobject Win32_Product |
Sort-Object Vendor, Name |
Format-Table Vendor, Name, Version -groupBy Vendor

Dissecting Win32_Product and Returning to Basics

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

See Any Updates and More PowerShell Scripts

Guy Recommends: WMI Monitor and It’s Free!Solarwinds Free WMI Monitor

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 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

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.  You can see its output list of programs is shorter than that of the above scripts.  Some of those missing programs could be the ones that you wish to identify and remove.

# PowerShell script to display a list of uninstallable programs

$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"

Guy Recommends: Tools4ever’s UMRAUMRA The User Management Resource Administrator

Tired of writing scripts? The User Management Resource Administrator solution by Tools4ever offers an alternative to time-consuming manual processes.

It features 100% auto provisioning, Helpdesk Delegation, Connectors to more than 130 systems/applications, Workflow Management, Self Service and many other benefits. Click on the link for more information onUMRA.

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


See more Microsoft PowerShell tutorials

PowerShell Tutorials  • Methods  • Cmdlets  • PS Snapin  • Profile.ps1  • Exchange 2007

Command & Expression Mode  • PowerShell pipeline (|)  • PowerShell ‘where‘  • PowerShell ‘Sort’

Windows PowerShell Modules  • Import-Module  • PowerShell Module Directory 

If you see an error of any kind, do let me know.  Please report any factual mistakes, grammatical errors or broken links.