PowerShell Ezine, Logon Scripts

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:
WMIC
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: SolarWinds Engineer's Toolset v10Engineer's Toolset v10

The Engineer's Toolset v10 provides a comprehensive console of utilities for troubleshooting computer problems.  Guy says it helps me monitor what's occurring on the network, and the tools teach me more about how the system itself operates.

There are so many good gadgets, it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, discovery, diagnostic, and Cisco tools.  Download your copy of the Engineer's Toolset v 10

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

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"

Footnote: This Ezine is Now Available on Twitter - ComputerPerfGuy

Guy's Humour Twitter Link


If you are looking for handy network utilities, try some of the free downloads at Tools4Ever


See more Microsoft PowerShell tutorials

Windows PowerShell Home  • Introduction  • Cmdlets  • Exchange 2007  • Profile.ps1  • $_.Pipeline

If you see an error of any kind, do let me know.  Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit.

 *


Google

Web  This website

Review of Orion NPMGuy Recommends: Orion's NPM - Network Performance Monitor

Orion's performance monitor is designed for detecting network outages. A network-centric view make it easy to see what's working, and what needs your attention.

This utility guides you through troubleshooting by indicating whether the root cause is faulty equipment or resource overload.

Download a free trial of the Network Performance Monitor

 

Home Copyright © 1999-2010 Computer Performance LTD All rights reserved

Please report a broken link, or an error.