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

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

问题描述

所以我尝试了很多不同的方法来从命令行运行 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"'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:\Users\test\Documents\test\line space\PS Script"未被识别为 cmdlet、函数、脚本文件或可运行程序的名称.检查名称的拼写,如果包含路径,请验证路径是否正确,然后重试.

<块引用>

Processing -File ''C:\Users\test\Documents\test\line space\PS Script'' failed: The given path's format is not supported ed.为 -File 参数指定有效路径.

我该如何解决这个问题?

解决方案

在您的示例中,您无缘无故地混用了引号和双引号.

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";)

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.

Here is this path:

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

I've tried these:

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'"

I get all these errors:

& : 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.

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.

How can I fix this?

解决方案

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天全站免登陆