簡體   English   中英

通過PowerShell卸載應用程序

[英]Uninstall Applications Via PowerShell

我已經工作了幾天,無論我如何運行和運行它,似乎都可以通過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應用程序列表中。

您可以檢查MSIInstaller事件以找到卸載失敗的線索:

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

您還可以使用/le '<logfilepath>'添加到您對msiexec.exe的調用中來記錄MSI活動,並檢查結果。

我相信msi安裝/卸載操作是異步的。 您可能必須在pssession中等待,直到安裝完成。

McAfee Agent有時需要frminst.exe /forceuninsall

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM