Powershell Start-Process命令参数转义


0

我尝试从Powershell会话中打开提升的Powershell。这有效:

powershell -NoExit -Command "Start-Process PowerShell -ArgumentList @('-NoExit','-NoProfile') -Verb RunAs"

这不是:

powershell -NoExit -Command "Start-Process PowerShell -ArgumentList @(`"-NoExit`",`"-NoProfile`") -Verb RunAs"

错误提示:

In Zeile:1 Zeichen:49
+ Start-Process PowerShell -ArgumentList @(-NoExit,-NoProfile) -Verb Ru ...
+                                                 ~
Argument in der Parameterliste fehlt.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument
+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingArgument

因此,报价不知所措。为什么?


第一行非常完美,第二行与第一行没有区别,不同位置的其他引号除外。您想达到什么目的?
Smeerpijp

我想以提升的权限来启动subshel​​l。这个问题的重点是关于为什么在一种情况下引号被剥夺,而在另一种情况下却不被剥夺。
罗伯特·库恩(RobertKühne)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.