Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Find an installation directory in the registry; more reliable than file system path search.
Gets the installation directory for a program in the registry.
Get-InstallationPath gets the installation path for a program in the InstallProperties registry key. This method is much more reliable and change-resistant than searching the file system with partial paths.
The function returs a custom object with the DisplayName, Publisher, and InstallationPath so you can confirm that the path returns is for the intended program.
If the script cannot find the installation path for the program, it generates a non-terminating error.
.PARAMETER ProgramName
Specify the name of the program installed on the local system. Get-InstallationPath returns the installation directory of the specified program. Wildcard characters are supported.
Get-InstallationPath -ProgramName "*PowerShell*Studio*"
DisplayName Publisher InstallPath
----------- --------- -----------
PowerShell Studio 2016 SAPIEN Technologies, Inc. C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2016\
if (($result = Get-InstallationPath -ProgramName "*PowerShell*Studio*").Publisher -like "*SAPIEN*")
{ $path = $result.InstallPath }
PS C:\> $path
C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2016\
This command checks the publisher value before saving the installation directory in the $path variable.
Get-InstallationPath -ProgramName NotThere
Get-InstallationPath : Cannot find installation directory for NotThere
At line:1 char:1
+ Get-InstallationPath -ProgramName NotThere
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-InstallationPath
Additional information about the function.
function Get-InstallationPath
[Parameter(Mandatory = $true)]
$result = @()
if ($inst = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\*\Products\*\InstallProperties" -ErrorAction SilentlyContinue)
$inst | Where-Object {
($DisplayName = $_.getValue('DisplayName')) -like $ProgramName
} |
ForEach-Object {
$result += [PSCustomObject]@{
'DisplayName' = $displayName
'Publisher' = $_.getValue('Publisher')
'InstallPath' = $_.getValue('InstallLocation')
Write-Error "Cannot get the InstallProperties registry keys."
if ($result)
return $result
Write-Error "Cannot get the InstallProperties registry key for $ProgramName"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.