Windows Powershell-Start Process ArgumentList只接受带空格的单个变量

Windows Powershell-Start Process ArgumentList只接受带空格的单个变量,windows,powershell,Windows,Powershell,我正在尝试从资源管理器启动脚本。我已经找到了解决方案,如果脚本没有任何参数,它就会工作 $file = [System.IO.Directory]::GetCurrentDirectory() + "\Trees.ps1" Start-Process powershell -verb runas -ArgumentList "-ExecutionPolicy UnRestricted -File `"$($file)`"" 然而,如果

我正在尝试从资源管理器启动脚本。我已经找到了解决方案,如果脚本没有任何参数,它就会工作

$file = [System.IO.Directory]::GetCurrentDirectory() + "\Trees.ps1"
Start-Process powershell -verb runas -ArgumentList "-ExecutionPolicy UnRestricted -File `"$($file)`""
然而,如果我像第一个一样添加额外的参数,它将停止工作。此代码抛出“字符串缺少终止符:”。错误

我使用的是期望变量的这种方式:

[Parameter(Mandatory=$True)]
[string]$Context,
如何在ArgumentList中传递多个带空格的变量?
我怀疑我应该以其他方式传递文件内容的参数,而不是仅仅传递文件名,但找不到解决方案。

除了Theo指出的回勾问题之外,
-context
应该跟在
-file
后面

-File
    Runs the specified script in the local scope ("dot-sourced"), so that the
    functions and variables that the script creates are available in the
    current session. Enter the script file path and any parameters.
    File must be the last parameter in the command, because all characters
    typed after the File parameter name are interpreted
    as the script file path followed by the script parameters.
所以你的命令行是

Start-Process powershell -verb runas -ArgumentList "-ExecutionPolicy UnRestricted -File `"$($file)`" -Context $($Context)"

除了西奥提到的背勾问题外,
-context
应该跟在
-file
后面

-File
    Runs the specified script in the local scope ("dot-sourced"), so that the
    functions and variables that the script creates are available in the
    current session. Enter the script file path and any parameters.
    File must be the last parameter in the command, because all characters
    typed after the File parameter name are interpreted
    as the script file path followed by the script parameters.
所以你的命令行是

Start-Process powershell -verb runas -ArgumentList "-ExecutionPolicy UnRestricted -File `"$($file)`" -Context $($Context)"

由于您使用的是外部进程调用,因此需要在内部使用双引号,而不是单引号。只需添加另一个双引号(
”),即可对双引号进行转义


由于您使用的是外部进程调用,因此需要在内部使用双引号,而不是单引号。只需添加另一个双引号(
”),即可对双引号进行转义


这些是围绕$context的单引号,而不是反勾号。这些是围绕$context的单引号,而不是反勾号。