我需要从Windows获取特定软件包的UninstallString。不幸的是,安装了许多不同版本的包,所以我需要通过包名来查询它。我已经找到了如何做这个这里和这里的例子。我编写了一个测试脚本来验证我正在获取正确的应用程序。这个测试脚本应该将应用程序的显示名称写入控制台。然而,它却是在写空白行。当我试图将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}"
}
}发布于 2016-02-17 16:23:14
替换这个
Write-Output "${app.DisplayName}"有了这个
Write-Output "$($app.DisplayName)"https://stackoverflow.com/questions/35461569
复制相似问题