Windows 使用Powershell从注册表返回密钥路径

Windows 使用Powershell从注册表返回密钥路径,windows,powershell,Windows,Powershell,我正在写一个脚本,可以从注册表中删除条目。问题在于:HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{NUMBER}中的端点不是常量,每次安装产品时都会更改。 我找到了一个类似的解决方案,并将脚本改为我自己。但是我仍然不知道如何准确地删除{NUMBER}文件夹中的内容 此时,脚本只能返回Publisher、DisplayName、DisplayVersion、UninstallString,但解决了此问题,以便脚本返回完整路径,

我正在写一个脚本,可以从注册表中删除条目。问题在于:
HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\{NUMBER}
中的端点不是常量,每次安装产品时都会更改。 我找到了一个类似的解决方案,并将脚本改为我自己。但是我仍然不知道如何准确地删除{NUMBER}文件夹中的内容

此时,脚本只能返回
Publisher、DisplayName、DisplayVersion、UninstallString
,但解决了此问题,以便脚本返回完整路径,或者至少返回这些记录所在文件夹的名称?最好的办法是移除

这是我的密码:

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

您没有提到PowerShell版本,我假设它是在Windows 10上运行的PowerShell 5.1,希望有帮助:

Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" 
我想你可以从结果中找到你想要的任何东西:
PSChildName
:您提到的{number}
InstallLocation
:插入目录的文件夹


至于
显示名称
显示版本
发布者
,等等,只需选择字段。

您没有提到PowerShell版本,我假设它是在Windows 10上运行的PowerShell 5.1,希望它有帮助:

Get-ItemProperty "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*" 
我想你可以从结果中找到你想要的任何东西:
PSChildName
:您提到的{number}
InstallLocation
:插入目录的文件夹


至于
显示名称
显示版本
发布者
,等等,只需选择字段。

可能这就是您正在寻找的解决方案:可能这就是您正在寻找的解决方案:@Andrej感谢您的反馈。@Andrej感谢您的反馈。