如何从命令行在路径中运行带有空格的Powershell脚本? [英] How to run a powershell script with white spaces in path from command line?

查看:499
本文介绍了如何从命令行在路径中运行带有空格的Powershell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试了多种方法从命令行运行Powershell脚本,每个方法都会返回一个错误。

So I've tried a bunch of different ways to run a powershell script from the command line and every single one returns an error.

这是路径:

C:\Users\test\Documents\test\line space\PS Script\test.ps1

我已经尝试过这些:

powershell -File '"C:\Users\test\Documents\test\line space\PS Script\test.ps1"'

powershell "& ""C:\Users\test\Documents\test\line space\PS Script\test.ps1"""

Powershell "& 'C:\Users\test\Documents\test\line space\PS Script\test.ps1'"

Powershell -File 'C:\Users\test\Documents\test\line space\PS Script\test.ps1'"

我得到所有这些错误:


& :术语 C:\用户\测试\文档\测试\行空间\PS脚本\不被视为cmdlet,函数,脚本文件或可运行程序的名称。名称的拼写,或者是否包含路径,请验证路径是否正确并重试。

& : The term 'C:\Users\test\Documents\test\line space\PS Script\' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

处理-文件'' C:\Users\test\Documents\test\linespace\PS Script\’失败:给定路径的格式不受支持。为-File参数指定有效路径。

Processing -File ''C:\Users\test\Documents\test\line space\PS Script\'' failed: The given path's format is not support ed. Specify a valid path for the -File parameter.

任何帮助将不胜感激!

推荐答案

在您的示例中,您无缘无故地将引号和双引号混合使用。

In your examples, you're mixing quotes and double quoting for no reason.

IF EXIST "C:\Users\test\Documents\test\line space\PS Script\test.ps1" (
  powershell -ExecutionPolicy Unrestricted -File "C:\Users\test\Documents\test\line space\PS Script\test.ps1"
)

这篇关于如何从命令行在路径中运行带有空格的Powershell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆