Listing & Quick Removal of Apps (Part 1)

Listing & Removing Software the PS way (Part 1)

So after playing with PowerShell 7 preview, I have a need to remove the preview side-by-side install. I installed it with Chocolatey so a quick removal with the choco cmdline would have been possible, but that's not the PS way.

If you don't know the registry hive can be accessed just like the C: drive. Look into PSdrives if you weren't aware of that. Also available is the certificate store which is really cool when working with SfB.

If your using WMI or CIM to query the Win32_Product class you should be aware of a bug/feature in the query that can cause your installed apps to repair themselves. This is not good in corporate environments where change control policies prevent you from doing this. So how do you interrogate a machine for installed applications without causing any unintended changes. Well, if you use SCCM then that product extends the WMI class to provide Win32_AddRemovePrograms. But what happens if not - let's explore the registry hive.

Within the Registry Hive is a "folder" that contains a lot of information about installed software.

HKLM: SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
Nice, so let's see if we can get to this location with PowerShell.

lets run:-

Get-childitem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

The screen will fly past with all the known applications installed. Generally all those you would normally see in add/remove programs.

Now lets get a list of applications and the version number. You will see that if we just run

Get-childitem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ | Select DisplayName,DisplayVersion
you will not get the output you expect. What we need to do is get access to the properties of each entry and the easiest way to do that is ask PowerShell to get them for you with the Get-ItemProperty cmdlet:-

Get-childitem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ | Get-itemProperty | Select DisplayName,DisplayVersion

Result

Now add this command to Invoke-Command -computers and you will be able to see a list of software available across multiple machines without relying on slow WMI/CIM queries and the dreaded reconfiguration feature.

See part two for how to then filter this list and magically uninstall applications from multiple machines.

And for those that missed it. Take a look at chocolatey, by far one of the best packaging systems I have used.

Comments