运行 文件路径中包含空格的 PowerShell 脚本

Run PowerShell script with spaces in the file path

如果变量 !batDir! 包含空格,我将无法使用以下批处理代码,例如W:\scripts windows\:

if /I "!i!" GTR "1" (
        Powershell "!batDir!ript.ps1 !test! '!testWithSpaces!' "
        goto :scriptEnd
)

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

您需要在 & 中使用引号。

Powershell "& '!batDir!ript.ps1' !test! '!testWithSpaces!' "

https://newbedev.com/how-to-run-a-powershell-script-with-white-spaces-in-path-from-command-line