通过PowerShell卸载应用程序

时间:2018-02-14 23:57:54

标签: windows powershell admin

我已经工作了几天了,无论我如何运行并运行它,它似乎通过PowerShell卸载程序并返回成功代码:

__GENUS          : 2
__CLASS          : __PARAMETERS
__SUPERCLASS     :
__DYNASTY        : __PARAMETERS
__RELPATH        :
__PROPERTY_COUNT : 1
__DERIVATION     : {}
__SERVER         :
__NAMESPACE      :
__PATH           :
ReturnValue      : 0
PSComputerName   :

这种情况发生在各种众所周知的难以删除的软件上,例如McAfee。

正在使用的命令是:

 Get-WmiObject -Class win32_product -Filter "Name like '%McAfee%'" | ForEach-Object {$_.Uninstall()}

我已尝试过各种脚本,解决方案以及这些内容的变体(如下所示)。

$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Yahoo Messenger" } | select UninstallString

$uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Yahoo Messenger" } | select UninstallString

if ($uninstall64) {
    $uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
    $uninstall64 = $uninstall64.Trim()
    Write "Uninstalling (x64)..."
    start-process "msiexec.exe" -arg "/X $uninstall64 /qb" -Wait
    }
if ($uninstall32) {
    $uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
    $uninstall32 = $uninstall32.Trim()
    Write "Uninstalling (x32)..."
    start-process "msiexec.exe" -arg "/X $uninstall32 /qb" -Wait}

即使是像Yahoo Messenger这样简单的东西,该命令也无法在以Powershell窗口的形式运行时以管理员身份卸载应用程序,但仍会返回成功代码和/或WMI应用程序列表中不再存在。

1 个答案:

答案 0 :(得分:1)

您可以检查MSIInstaller事件以找到卸载失败的原因:

Get-WinEvent -computername <computername> -ProviderName MSIInstaller -Maxevents 30

您还可以在/le '<logfilepath>'调用中添加msiexec.exe的情况下记录MSI活动,并检查结果。

我相信msi安装/卸载操作是异步的。您可能需要在pssession中等待,直到安装完成。

McAfee Agent有时需要删除frminst.exe /forceuninsall

相关问题