从PowerShell运行可执行文件不适用于path中的空格

在PowerShell提示符下:

\Windows\system32\mspaint.exe 

将运行Paint。 所以将

 Invoke-Expression -command "\Windows\system32\mspaint.exe" 

但是如果PowerShell在path中有空格,

 Invoke-Expression -command "\install\sub directory\test.bat" 

哪位抱怨:

 The term '\install\sub' is not recognized as the name of a cmdlet, function, script file, or operable program. 

我错过了什么?

根据Technet上的这篇文章,用双引号括住path是不够的。

您尝试使用的path必须在目录前有一个 (&符号),否则它将不起作用。

例如:

 Invoke-Expression -command & "\install\sub directory\test.bat" 

最简单的方法是使用invoke操作符:

 &'String containing the path' 

注意,要启动一个可执行文件, Invoke-Expression实际上是错误的cmdlet,最好使用Start-Process