
close
close
In the first part of this series we looked at using WMI to identify installed applications. While I believe that is an effective method, it can be painfully slow. Fortunately, there is another path to explore and that is by searching the registry. Most applications that are installed via an installation package will record uninstalled information in the registry. There’s no guarantee of knowing if something you find in the registry is in fact still installed, and of course, not every installed application will record itself. But let’s look at how you could query this information because I’m sure more than a few of you will find it useful.
It is not too difficult to query the registry with PowerShell. However, you can only query using the Registry PSDrive on the local computer. To query remote computers, simply wrap the commands I’ll be showing you in a script block and use the Invoke-Command. In fact, let’s jump right to it, and here’s a one-line command to list names of applications that can be uninstalled.
dir HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | Get-Itemproperty -Name Displayname | Select Displayname
To run on a remote computer, use something like this:
Invoke-Command –scriptblock {dir HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | Get-Itemproperty -Name Displayname | Select Displayname } –computername Desk01
There is a potential problem here in that some registry entries might not have a Displayname property, which will result in an error. If you are merely looking for a quick list, you can substitute the registry key name for any missing displayname properties.
dir HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
Get-Itemproperty | Select @{Name="Name";Expression={
if ($_.displayname) { $_.Displayname } else { $_.PSChildname}
}} | Out-GridView -title "Uninstalls"
Here’s my result.
Uninstall results after substituting the registry key name for any missing displayname properties. (Image Credit: Jeff Hicks)
dir HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall -PipelineVariable p |
Get-ItemProperty | Select @{Name="Path";Expression={$p.name}},Displayname,DisplayVersion,
Publisher,InstallDate,InstallLocation,Comments,UninstallString
Using the pipelinevariable common parameter in PowerShell to obtain more information about installed software. (Image Credit: Jeff Hicks)
$data = dir HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |
where {$_.name -notmatch '(\.)?KB\d+'} -pv p |
Get-ItemProperty | Where {$_.displayname -notmatch "KB\d{5,}"} |
Select @{Name="Path";Expression={$p.name}},Displayname,DisplayVersion,
Publisher,InstallDate,InstallLocation,Comments,UninstallString
My solution is to filter out using regular expression patterns, any entry that includes the string KB followed by a series of numbers. My result will be similar to the screenshot above, but without any of the update entries. The reason I saved the result to a variable is because I want to add to it. What am I adding? On 64bit machines there is another registry location to check: HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall. I am going to repeat my command using this new path and append the results to $Data.
$data += dir HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
where {$_.name -notmatch '(\.)?KB\d+'} -pv p |
Get-ItemProperty | Where {$_.displayname -notmatch "KB\d{5,}"} |
Select @{Name="Path";Expression={$p.name}},DisplayName,DisplayVersion,
Publisher,InstallDate,InstallLocation,Comments,UninstallString
Now I can do whatever I want with $data, and I should have a good feel what applications are installed or at least what can be uninstalled. To query a remote machine, I can wrap these commands inside a script block and use the Invoke-Command.
Finally, there is one more location in the registry where you might find this type of information and that is per user. You can use similar registry query techniques for HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall.
dir HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall -pv p |
get-ItemProperty |
Select @{Name="Path";Expression={$p.name}},Displayname,DisplayVersion,
Publisher,InstallDate,InstallLocation,Comments,UninstallString
My experience with applications under HKCU is that I don’t need to filter out anything.
Querying installed applications in the HKCU with PowerShell. (Image Credit: Jeff Hicks)
More in PowerShell
Most popular on petri