是否可以将PowerShell命令行拆分为多行?
在Visual Basic中,我可以使用下划线(_)继续下一行中的命令.
我有一个如下所示的批处理脚本:
@echo off
:: Starts a PowerShell session that starts a PowerShell process with administrator privileges
powershell -noprofile -command "&{$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -verb RunAs -PassThru;$process.WaitForExit();}"
Run Code Online (Sandbox Code Playgroud)
为了便于阅读,我想将"&{...}"内的代码拆分为多行.
这篇文章说使用尾随反引用应该可以解决问题,但是当我写下:
powershell -noprofile -command "&{`
$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -verb RunAs -PassThru;`
$process.WaitForExit();`
}"
Run Code Online (Sandbox Code Playgroud)
...也就是说,我用尾随反引号结束每一行,然后我收到以下错误:
Incomplete string token.
At line:1 char:4
+ &{` <<<<
+ CategoryInfo : ParserError: (`:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : IncompleteString
'$process' is not recognized as an …Run Code Online (Sandbox Code Playgroud) 当我在powershell控制台中输入它时
$test=@'
Test
Test'@
Run Code Online (Sandbox Code Playgroud)
并输入几次,它继续打印
>>
Run Code Online (Sandbox Code Playgroud)
所以我永远无法完成命令.
该怎么办 ?