This is one of those things that can be accomplished in a more direct route but it’s so cool that I need to show you how to do this.
Microsoft Powershell is an extremely nimble and robust command-line tool that lets you automate mundane tasks on local and remote machines.
The real power from Powershell stems from the command utilities that let you do stuff such as systems administration and importing data.
Today I just want to focus on one little command that lets you list all the programs currently installed on your computer.
Sure, you could take the circuitous path of pressing the Windows Key and typing
programs and features
But I contend that using Powershell to accomplish the same task is the recondite path to geekhood.
We’re going to use the Get-WmiObject cmdlet to list all the programs currently installed on your computer. Then I’ll show you how to save the results to a file and we’ll finish with a neat trick that compares the installed programs between two PC’s.
Hit the Windows icon on your keyboard, and type:
You should the familiar blue icon appear in the search results.
Open it up and when the “BlueScreen of Life” appears type in the following command and wait about 5 seconds:
Get-WmiObject -Class Win32_Product
I call it the “BlueScreen of Life” because it’s the complete antithesis to its morbid cousin who loves to crash your computer: the notorious BlueScreen of Death.
The above Get-WmiObject command we typed above references the Win32_Product class which represents products as they are installed by the Windows installer.
But our results are less than satisfying.
The patent problem with this command is that it’s virtually unintelligible. There’s way too much information and each software package is sorted by an arcane identifying number that is utterly useless to mere mortals like you and me.
Let’s tighten up our command a little bit:
Get-WmiObject -Class Win32_Product | Select-Object -Property Name
Do you see that Select-Object -Property Name business?
We’re just telling PowerShell to refine the results to just the Name. That is, we only care about the name of the application. All that other crap about Vendor, Version and Caption is superfluous.
This is better but there are still two issues:
- Why are the programs still out of order?
- Why does Adobe Indesign CC 2014 show up in Programs and Features but not PowerShell?
The issue is that programs are still listed by the now invisible identifying number. So how do we get it to sort by the application name?
Just pipe the results to the Sort-Object cmdlet by sticking it on the end of the last command:
Get-WmiObject -Class Win32_Product | Select-Object -Property Name | Sort-Object Name
Ahh, that’s better but Adobe Indesign CC 2014 is still missing from the list.
What’s up with that?
The Win32_Product class can only display applications installed using the Windows installer. The Adobe application suite is provisioned through the Creative Cloud application suite which isn’t based on the Windows installer framework. The concomitant result is that the Adobe product line doesn’t show up in our PowerShell output.
This is unfortunately one of the limitations of this PowerShell command; however, if you know how to list all the applications please let me know in the comments below.
So what else can you do besides shoot off an alphabetical list of most of your programs?
Well, you can pipe it to a text file by simply adding the greater than sign and the full path to a new file. If the file doesn’t already exist, PowerShell will automatically create it for us.
Get-WmiObject -Class Win32_Product | Select-Object -Property Name | Sort-Object Name > C:\Users\vhudson\Desktop\desktop-apps.txt
Now if you want to compare the text files we can use the Compare-Object cmdlet with -ReferenceObject and -DifferenceObject to accentuate the differences between them.
Alright so I’ve got two files.
- desktop-apps.txt shows all the windows installer based apps on my PC
- peters-pc.txt has all the windows apps from a different PC
Here’s how to compare the two:
Compare-Object -ReferenceObject (Get-Content C:\Users\vhudson\Desktop\desktop-apps.txt) -Difference Object (Get-Content C:\Users\vhudson\Desktop\peters-pc.txt)
This might look a little crazy but if you study it for a few seconds you can see I’m using the Get-Content cmdlet to grab the content of each text file and then the -ReferenceObject and -DifferenceObject options provide the reference points for the SideIndicator arrows.
We defined the apps on my computer, desktop-apps.txt, as the reference set and the apps on Peter’s computer as the difference set.
In the SideIndicator column, when the arrow symbol points to the left like this (<=) it means that the value, in this case the application name, only appeared in the reference set.
Similarly, where the arrow points to the right (=>) the application name only appeared in the difference set, Peter’s computer. If both sets are identical you’ll see the == symbol.
That’s all there is to it.
One caveat is that you can keep using the Win32_Product class like we did in this tutorial; however, some experts say that it’s clunky and therefore not very efficient in a production environment.
Since we’re only using this on our local computer it shouldn’t be a big deal but it’s worth nothing that it might not be apt across networked environments.
According to Microsoft Scripting guru Ed Wilson, it’s more efficient to use the Win32Reg_AddRemovePrograms class like this:
Get-WmiOBject -Class Win32Reg_AddRemovePrograms
However Win32Reg_AddRemovePrograms isn’t a standard Microsoft class and is only available by installing System Center 2012.
Also known as System Center Configuration Manager, SCCM is a software suite that lets you do a bunch of remote administration stuff such as push software, install updates and run various reports.
SCCM used to be called Microsoft SMS but was rebranded as SCCM in 2007.
You’ll need to have this installed before you can start using Win32Reg_AddRemovePrograms. If you don’t have it, don’t fret just keep using Win32_Product in non-production environments and you’ll be fine.