使用Powershell

时间:2018-05-20 09:10:28

标签: windows powershell

我正在编写一个能够从注册表中删除条目的脚本。问题是:HKCU:\Software\Microsoft\Windows\ CurrentVersion\Uninstall\{NUMBER}中的端点不是常量,并且每次安装产品​​时都会更改。 我找到了问题here的类似解决方案,并将脚本更改为自己。但我仍然不知道如何准确删除 {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)"
    }
}

1 个答案:

答案 0 :(得分:2)

您没有提及PowerShell版本,我认为它是在Windows 10上运行的PowerShell 5.1,希望有所帮助:

<p:commandLink styleClass="btn btn-success" process="@this"
    onclick="viewModal(#{status.index});">
    <h:outputText value="ADD" />
                                <f:setPropertyActionListener
        value="#{teacher.id}" target="#{ViewTeacher.selectedTeacher}" /> 

        </p:commandLink>

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

关于InstallLocationdisplay namedisplay version等,只需选择该字段。

相关问题