PowerShell – Get List of Installed Programs


ps_logo_cowboy

As I was spinning in the wheel of my cage today, I started putting together some ideas for a post that was motivated by one objective, namely, listing the GUID of a particular software product that is installed on a computer using Windows PowerShell.  However, this post quickly spun out of control into a larger Windows PowerShell reference with lots of examples of how to display, format, and sort installed software programs on a local computer, remote computer, and multiple remote computers!

A “Globally Unique Identifier” (or GUID) is a 128-bit (16 byte) number string used by software programs to uniquely identify the location of a data object.  Some examples of data that include GUIDs are streaming media files, Windows registry entries, database keys, and various file types.  GUIDs are typically written in hexadecimal notation, containing 32 digits, and look like this:

Example of GUID (or “IdentifyingNumber” in WMI):
{26A24AE4-039D-4CA4-87B4-2F83218066F0}

Why do I care so much about some GUID-thingamajig Believe it or not, this string of hexadecimal digits is useful when you’re trying to install or uninstall particular programs from multiple computers over the network.

Why do you want to read the rest of this postI put together this post to help you quickly find and list the following information on local or remote computers using Windows PowerShell:

  1. Installed software programs with respective GUID (a.k.a. “IdentifyingNumber”)
  2. Uninstall string or path of installed software programs

Note:  You may have heard that querying WMI (i.e., using the cmdlet, “Get-WmiObject”) for installed software DOES NOT perform as well as querying the Windows Registry.  The registry approach is recommended instead of WMI because it’s much faster and returns more accurate data.  Later in this post, I will introduce you to a neat script developed by Jaap Brasser that uses Windows PowerShell to query the registry instead of WMI.


“Just give me A quick dump of installed programs!”

Okay, okay, okay, launch Windows PowerShell as “Administrator” and try this:

PowerShell Example for Local Computer:
Get-WmiObject -Class Win32_Product -Computer .

PowerShell Example for Remote Computer(s):
Get-WmiObject -Class Win32_Product -Computer computer1, computer2

This WMI query lists the applications installed with the Windows Installer on a local or remote system.

List_Software_PS_WMI_1


“The output needs to be formatted!”

Okay, okaaay, okay, launch Windows PowerShell as “Administrator” and try the following:

Get-WmiObject -Class Win32_Product -Computer . | Format-Table IdentifyingNumber, Name, LocalPackage

List_Software_Guid_MSI

Get-WmiObject -Class Win32_Product -Computer . | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize

List_Software_Format_AutoSize

If you want to list only the properties that interest you, use the Property parameter of the formatting cmdlets to list the desired properties.

Get-WmiObject -Class Win32_Product -ComputerName . | Format-List -Property Name,InstallDate,InstallLocation,PackageCache,Vendor,Version,
IdentifyingNumber

If you want just the names of installed applications, a simple Format-Wide statement simplifies the output:

Get-WmiObject -Class Win32_Product -ComputerName . | Format-Wide -Column 1

“I NEED ALL THE INFORMATION!”

Okay, okay, okaaay, launch Windows PowerShell as “Administrator” and try this out:

Get-WmiObject -Class Win32_Product -ComputerName . | Format-List 
-Property *

This WMI query displays all the properties of the Win32_Product object to the display by using the Properties parameter of the formatting cmdlets, such as the Format-List cmdlet, with a value of * (all).

List_Software_ALL_Info


“How Do I Search for JUST One PRogram?”

If you want to start filtering the output, then launch Windows PowerShell as “Administrator” and try something like the following:

Get-WmiObject -Class Win32_Product -ComputerName . | Where-Object -FilterScript {$_.Name -eq "Microsoft .NET Framework 4.5.2"} | Format-List -Property *

OR

Get-WmiObject -Class Win32_Product -ComputerName . -Filter "Name='Microsoft .NET Framework 4.5.2'"| Format-List -Property *

If you’re not sure of the exact name of the program, then you can try something like the following:

Get-WmiObject -Class Win32_Product -ComputerName . | Where-Object -FilterScript {$_.Name -like "Microsoft .NET Framework*"} | Format-List -Property *

If you want all the software products from a particular vendor, then you can try something like the following:

Get-WmiObject Win32_Product -Computer . -Filter "vendor = 'microsoft corporation'" | Select-Object identifyingNumber, Name, Vendor, Version, Caption

“how do I output ALL this INFO to excel?!”

If you want to export this information, launch Windows PowerShell as “Administrator” and try adding this:

Get-WmiObject -Class Win32_Product -Computer . | select-object IdentifyingNumber,Name,Vendor,Version,Caption,LocalPackage | Export-CSV -path c:\ListSoftwareResults.csv -notypeinformation

Note:  You must include the -notypeinformation (or simply, -notype) parameter with the Export-Csv cmdlet if don’t wish to see the .NET object type in the first row of your output file (i.e., “#TYPE…”)


“How do you query multiple computers from a text file?”

If you want to hit a list of computers, then launch Windows PowerShell as “Administrator” and do something like the following:

Get-Content -Path c:\Computers.txt | ForEach-Object {Get-WmiObject -Class Win32_Product -ComputerName $_} | Where-Object -FilterScript {$_.Name -like "*.NET Framework*"} | Format-List -Property *

 


How Do I Get a List of Installed Software Programs from the Registry Instead of WMI?

Jaap Brasser over at Microsoft TechNet “Script Center” wrote a neat little Windows PowerShell Script called, “Get-RemoteProgram.ps1.”  Jaap’s PS script will generate a list of installed programs on a local or remote computer (as well as multiple remote computers) by querying the registry!  The script also allows for the retrieval of additional properties such as the uninstall string of an application.

Name: Get-RemoteProgram
Author: Jaap Brasser
Version: 1.2.1
DateCreated: 2013-08-23
DateUpdated: 2015-02-28
Blog: http://www.jaapbrasser.com

Click here to download:  Get-RemoteProgram.ps1


Step #1:  Copy “Get-RemoteProgram.ps1” into Your Working Directory and Remember to Dot-Source the Script File!


PS_Dot_Sourcing


Note:  There is a space between the two dots!  You need to load the function into memory by dot-sourcing the script file which makes the “Get-RemoteProgram” function available in your current session of Windows PowerShell. 


Step #2:  Start with the Basics


Returns a list of installed programs on the local computer:

Get-RemoteProgram

Returns a list of installed programs on Server01 and Server02:

Get-RemoteProgram -ComputerName Server01,Server02

Queries the list of programs from Server01 and returns the displayversion and versionmajor subkeys from the registry for each installed program:

Get-RemoteProgram -ComputerName Server01 -Property DisplayVersion,VersionMajor

Returns the installed programs on server01/02 that are passed on to the function through the pipeline and also returns the uninstall string for each program:

'server01','server02' | Get-RemoteProgram -Property Uninstallstring

Step #3:  Move Beyond the Basics


How to run “Get-RemoteProgram” against a list of computers (i.e., c:\Computers.txt) in order to display the computers with Microsoft Office installed:

Get-Content -Path c:\Computers.txt | ForEach-Object -Begin {. .\Get-RemoteProgram.ps1} -Process {Get-RemoteProgram -ComputerName $_} | Where-Object {$_.ProgramName -like ‘*Office*’} | Select-Object -Property ComputerName -Unique


How to run “Get-RemoteProgram” against Windows 7 computers in Active Directory (AD):

Get-ADComputer -Filter {OperatingSystem -Like “Windows 7*”} | Select-Object -ExpandProperty Name | Get-RemoteProgram | Select-Object ProgramName,ComputerName


How to output the results to CSV (Comma Separated Value) File.

Get-Content -Path C:\ComputerList.Txt | ForEach-Object {Get-RemoteProgram -ComputerName $_} | Export-Csv -Path C:\InstalledPrograms.csv -NoTypeInformation


Step #4:  Let’s End with Some Advanced Sorting Results!


Georges Zwingelstein created the following command strings to sort by Installed programs, Installed updates, or Installed components.

Sort by Installed programs:

Get-RemoteProgram -Property Publisher,InstallDate,DisplayVersion,InstallSource,IsMinorUpgrade,ReleaseType,ParentDisplayName,SystemComponent | Where-Object {[string]$_.SystemComponent -ne 1 -and ![string]$_.IsMinorUpgrade -and ![string]$_.ReleaseType -and ![string]$_.ParentDisplayName} | Sort-Object ProgramName

Sort by Installed updates:

Get-RemoteProgram -Property Publisher,InstallDate,DisplayVersion,InstallSource,IsMinorUpgrade,ReleaseType,ParentDisplayName,SystemComponent | Where-Object {[string]$_.SystemComponent -ne 1 -and ([string]$_.IsMinorUpgrade -or [string]$_.ReleaseType -or [string]$_.ParentDisplayName)} | Sort-Object ParentDisplayName,ProgramName

Sort by Installed Components:

Get-RemoteProgram -Property Publisher,InstallDate,DisplayVersion,InstallSource,IsMinorUpgrade,ReleaseType,ParentDisplayName,SystemComponent | Where-Object {[string]$_.SystemComponent -eq 1} | Sort-Object ProgramName

¯\_(ツ)_/¯

“What else do you got?”  Stay tuned . . .


Facebook Comments