在调用msiexec时从powershell中的路径中转义空间

时间:2015-08-07 00:08:12

标签: powershell

问题是卸载文件的路径中有一个空间存储在变量$uninstall32

C:\Program Files (x86)\Notepad++\uninstall.exe

如何使用msiexec转义空间并执行卸载文件?

$softwaretoRemove = "Notepad\+\+"
$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match $softwaretoRemove } | select UninstallString

$uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstall32 = $uninstall32.Trim()
Write $uninstall32
start-process "msiexec.exe"  -ArgumentList "$uninstall32 /uninstall /quiet" 

1 个答案:

答案 0 :(得分:0)

你必须用引号包围路径:

start-process "msiexec.exe"  -ArgumentList """$uninstall32"" /uninstall /quiet"