Search code examples
windowspowershell

Check, if an specific App is installed using PowerShell


I want to check via PowerShell, if a specific product (like "Office" or "Visual Studio") is installed on the target computer, but I can not use any 3rd party PowerShell modules (because I want to give the script to some friends and here the script should work out of the box.

I found this PowerShell script that returns a list of all apps (also the path):

$INSTALLED = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, InstallLocation
$INSTALLED += Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, InstallLocation
$INSTALLED | ?{ $_.DisplayName -ne $null } | sort-object -Property DisplayName -Unique | Format-Table -AutoSize 

The only thing I need is to get the file-path (InstallLocation) for a specific product and store this in a Variable. I have no idea, how to perform this.


Solution

  • You can use get-package. Not all apps have an installlocation entry.

    get-package 7-zip* | % { $_.metadata['installlocation'] }
    
    C:\Program Files\7-Zip\
    

    Note that Netbeans installs break get-itemproperty because of the invalid NoModify registry entry [still true in 2023]. [NETBEANS-2523] Netbeans 64-bit creates invalid nomodify value in windows registry for years - ASF JIRA

    Get-ItemProperty : Specified cast is not valid.
    At line:1 char:1
    + Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Unin ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-ItemProperty], InvalidCastException
        + FullyQualifiedErrorId : System.InvalidCastException,Microsoft.PowerShell.Commands.GetItemPropertyCommand