使用Powershell从Registry中检索应用程序的DisplayName / UninstallString

时间:2016-02-17 15:55:10

标签: powershell

我需要从中获取特定软件包的UninstallString Windows注册表。不幸的是,有许多不同的版本 安装的包,所以我需要按包名查询它。我找到了 有关如何执行此操作的示例herehere。我写了一个测试脚本 验证我正在抓取正确的应用程序。这个测试脚本 将应用程序的显示名称写入控制台。然而, 而是写一个空白行。当我尝试时,我得到了相同的结果 将UninstallString写入控制台。

$PATHS = @("HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
           "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
$SOFTWARE = "SOFTWARE_NAME"

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

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

1 个答案:

答案 0 :(得分:1)

替换此

Write-Output "${app.DisplayName}"

用这个

Write-Output "$($app.DisplayName)"
相关问题