Андрей Ка
Андрей Ка

Reputation: 774

Return key path from Registry Using Powershell

I am writing a script that will be able to erase entries from the registry. The problem is that the endpoint in: HKCU:\Software\Microsoft\Windows\ CurrentVersion\Uninstall\{NUMBER} is not constant and changes each time the product is installed. I found a similar solution to the problem here, and changed the script to myself. But I still do not know how to delete exactly what is in the {NUMBER} folder .

At this time, the script can return only Publisher,DisplayName,DisplayVersion,UninstallString but resolves the problem so that the script returns the full path, or at least the name of the folder where these records are located? And would the best to be removed?

Here is my code:

$PATHS = @("HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\")
$SOFTWARE = "APPLICATION"

ForEach ($path in $PATHS) {
    $installed = Get-ChildItem -Path $path |
                 ForEach { Get-ItemProperty $_.PSPath } | 
                 Where-Object { $_.DisplayName -match $SOFTWARE } |
                 Select-Object -Property Publisher,DisplayName,DisplayVersion,UninstallString

    ForEach ($app in $installed) {
        Write-Output "$($app.DisplayName)"
    }
}

Upvotes: 0

Views: 286

Answers (1)

Chenry Lee
Chenry Lee

Reputation: 380

You didn't mention the PowerShell version, I assume it's PowerShell 5.1 running on Windows 10, wish it help:

Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" 

I think you can find whatever you want from the result:
PSChildName: the {number} you mentioned
InstallLocation: the folder where insatlled

As to display name, display version, publisher, etc, just pick the field.

Upvotes: 2

Related Questions