powershell - 如果文件名包含空格,则嵌入式PowerShell命令将不起作用

标签 powershell powershell-2.0 powershell-3.0

我知道这是一个奇怪的用例,但我需要在新流程中像这样执行,并且要一行完成。我花了很长时间才到达这个地方。为此,我已经把头发扯了好几个小时了……请帮助!
此命令在powershell和cmd中有效:

powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file C:\Temp\Test.ps1').Id"
此命令可在Powershell中使用,但不能在cmd中使用(找不到文件):
powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file `"C:\Temp\Test.ps1`"').Id"
当我在文件名中添加空格时,在PowerShell或cmd中找不到该文件(该文件确实存在):
powershell -command "(start-process -PassThru PowerShell -ArgumentList '-file `"C:\Temp\Test 1.ps1`"').Id"

最佳答案

您可以从命令提示符直接运行它:

start "" powershell -file "C:\Temp\test.ps1"
这将在新窗口中启动该过程。

关于powershell - 如果文件名包含空格,则嵌入式PowerShell命令将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64000941/

相关文章:

powershell - 从哈希表中删除重复值

rest - Powershell 3.0 Invoke-WebRequest HTTPS 在所有请求上都失败

powershell - 如何使用Powershell将\\server\Share $替换为D:

powershell - 使用 powershell 从 TFS 2010 checkout 文件

powershell - 组合链接的对象数组

powershell - 如何更新本地用户组的用户名?

windows - 无法从站点克隆 git 存储库

powershell - 使用驱动器号通配符启动进程

powershell - 使用 SAS token 上传 Blob 内容

linux - 运行powershell脚本而不添加publishsettings文件