简体   繁体   中英

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)"
    }
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM