Powershell - 查找卸载字符串并执行

问题描述 投票:0回答:1

我正在尝试编写一个脚本,该脚本将被推送到所有域计算机,以识别 Adobe 注册表项,并通过相应的卸载字符串卸载 Adobe Flash 的注册表项。

我使用以下命令来获取与 Adobe 关联的任何注册表项:

Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match "Adobe"} | Select-Object -Property DisplayName, UninstallString

以上内容可根据需要运行并提取 Adobe Keys,但我不想为所有这些密钥运行 UninstallString,而只想为 Adobe Flash Player 运行 UninstallString。

我已尝试以下方法来尝试仅提取包含“Adobe Flash Player”的键,但我不断收到错误:

Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName -match "Adobe" } | Select-Object -Property DisplayName, UninstallString |

Foreach-object{if ($_.GetValue('DisplayName') -like "Adobe Flash Player"){

$uninstall = $_.GetValue('UninstallString')

cmd /c $uninstall
}
}

Method Error

powershell registry
1个回答
0
投票

关键是要避免同时使用

Get-ItemProperty
Select-Object
,因为为了在管道末尾的
$_.GetValue(...)
调用中调用
ForEach-Object
,您需要由 Microsoft.Win32.RegistryKey
 输出的原始 
Get-ChildItem
 实例:

Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall,
              HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
  Where-Object { $_.GetValue('DisplayName') -match 'Adobe Flash Player' } | 
  ForEach-Object { 
    cmd /c $_.GetValue('UninstallString') 
  }
© www.soinside.com 2019 - 2024. All rights reserved.