Guy recommends :
Free Solarwinds
VM Console

Solarwinds VM Console Free Download

Find out which of your VMs are a waste of space and which VMs need more resources.



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: WMI Monitor and It's Free!Solarwinds Free WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft 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.

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   • WMI Services   • Win32_ComputerSystem

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

WMI Disk   • DNS   • PowerShell -Filter   • Windows PowerShell   • Memory

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.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

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

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft operating systems.

Fortunately, Solarwinds have created the Free WMI Monitor so that you can actually see and understand these gems of performance information.  Take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

 

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

Please report a broken link, or an error.