【发布时间】:2019-07-10 21:40:02
【问题描述】:
我现在遇到的问题是,当我通过 PowerShell 运行代码时,它正在更改卸载字符串的值并在其前面添加变量名。我希望的结果是这样的。
MsiExec.exe /X{2C5B24AD-9F13-52A1-KA2N-8K4A41DC9L4G}
但是在将/I 替换为/X 并执行.Trim() 之后,我从变量中得到的结果如下:
@{UninstallString=/X{2C5B24AD-9F13-52A1-KA2N-8K4A41DC9L4G}}
所以我想知道你们是否能够从我下面的代码中告诉我哪里出错了。
我必须将/I 替换为/X,因为卸载字符串首先会像MsiExec.exe /I{2C5B24AD-9F13-52A1-KA2N-8K4A41DC9L4G} 这样返回,而我正在尝试卸载,而不是安装。
if ($Uninstall_str) {
#run uninstall here
try {
$Uninstall_str = $Uninstall_str -replace 'MsiExec.exe /I', '/X'
$Uninstall_str = $Uninstall_str.Trim()
Start-Process "msiexec.exe" -Arg "$Uninstall_str /qb" -Wait
} catch {
Write-Output $_.Exception.Message
Write-Output $_.Exception.ItemName
Write-Warning "Error unintalling."
}
}
【问题讨论】:
标签: powershell