[英]Return key path from Registry Using Powershell
我正在编写一个脚本,该脚本将能够从注册表中删除条目。 问题在于, 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
:安装位置的文件夹
至于display name
, display version
, publisher
等,只需选择该字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.