通过Powershell脚本(MSIEXEC)卸载补丁

时间:2018-07-18 11:58:37

标签: powershell parameters patch uninstall 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"""

请帮忙,我已经尽我所能找到了一切。.

谢谢。

0 个答案:

没有答案
相关问题