首页 > 解决方案 > 通过 powershell 脚本 (MSIEXEC) 卸载补丁

问题描述

我对powershell有点陌生,我试图自动化一个卸载补丁,这样我就可以安装另一个补丁(使用jenkins等~)。

我有这个脚本,它可以获取 ProductID 编号,并且我也有补丁 .msp 文件的路径。将这些变量传递给 msiexec 命令不起作用。我一直收到错误:“无法打开此安装包。请验证该包是否存在~”。

虽然,如果我在不将变量传递给 msiexec 的情况下运行命令,它可以工作。

这是我的脚本:

    $PATHPreviousPatch = "<>" #this is where I keep the .msp files to the patch that im trying to uninstall

    $IdNumber = Get-WmiObject -Class Win32_Product | Where-Object -FilterScript {$_.Name -eq "%product Example%"} | Format-List -Property IdentifyingNumber
    $strProductCode = $IdNumber | Out-String

    $strProductCode -match "IdentifyingNumber : (?<content>.*)"
    $strProductCode = $Matches['content']

    [string]$AppMSP = Get-ChildItem $PATHPreviousPatch| Where-Object {$_.Name -match "%appmsp%.msp"}
    $fullUninstallPath = $PATHPreviousPatch + $AppMSP #just to get the full path to the MSP file

    msiexec /package `'$strProductCode`' /uninstall """$fullUninstallPath"""

请帮忙,我已经尝试了我能找到的一切..

提前致谢。

标签: powershellparameterspatchuninstallationwindows-installer

解决方案


推荐阅读