【问题标题】:Powershell unable to uninstall silentlyPowershell 无法静默卸载
【发布时间】:2018-07-10 02:27:09
【问题描述】:
Start-Process -FilePath $application.UninstallString -ArgumentList "/q" -Wait -NoNewWindow

Start-Process -FilePath $application.UninstallString -ArgumentList "/s" -Wait -NoNewWindow

Start-Process -FilePath $application.UninstallString -ArgumentList "-q" -Wait -NoNewWindow

我尝试使用上述命令卸载应用程序,但是当我运行它时,会提示确认窗口,我想阻止该窗口显示。

【问题讨论】:

  • 这似乎更像是安装程序的问题,而不是与 PowerShell 相关的问题(无论如何)。无论哪种方式,两者都可能与 SO 无关。

标签: powershell


【解决方案1】:

PoSH 只需启动安装程序/卸载程序(.msi、.exe)。如果安装程序/uininstaller 没有静默选项,PoSH 对此无能为力。 RegKey 卸载字符串仅调用用于部署应用程序的原始安装程序。

查看此帖子进行类似讨论。

How can I uninstall an application using PowerShell?

Using the WMI object takes forever. This is very fast if you just know the name of the program you want to uninstall.
$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "SOFTWARE NAME" } | select UninstallString
$uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "SOFTWARE NAME" } | select UninstallString

if ($uninstall64) {
$uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstall64 = $uninstall64.Trim()
Write "Uninstalling..."
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..."
start-process "msiexec.exe" -arg "/X $uninstall32 /qb" -Wait}

其他示例:

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/60e06261-f134-41e8-9f99-6bada23a6f02/using-registry-uninstallstring-to-remove-software?forum=winserverpowershell

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

ForEach ($ver in $javaVer) {

    If ($ver.UninstallString) {

        $uninst = $ver.UninstallString
        & cmd /c $uninst /quiet /norestart
    }

}

通过以下方式在远程或本地计算机上搜索和卸载软件 电源外壳

此脚本搜索并尝试卸载某个软件 按产品名称。它在 SCCM 客户端的 WMI 类中查询 产品,找到卸载字符串并执行卸载字符串。

https://gallery.technet.microsoft.com/scriptcenter/Search-for-and-Uninstall-8c2c457e

【讨论】:

    猜你喜欢
    • 2020-05-30
    • 1970-01-01
    • 2017-09-10
    • 2011-09-11
    • 2022-12-09
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 2011-06-26
    相关资源
    最近更新 更多