У меня есть пакетный скрипт, который выглядит следующим образом:Powershell -command над многократным линии
test.bat
@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();}"
Я хотел бы разделить код внутри "& {...} «над несколькими линиями для удобочитаемости.
This пост говорит, что с помощью трейлинг обратной одиночных кавычек должно сделать трюк, но когда я пишу:
powershell -noprofile -command "&{`
$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -verb RunAs -PassThru;`
$process.WaitForExit();`
}"
... то есть, я заканчиваю каждую строку с завершающей кавычкой, то я получаю следующее сообщение об ошибке :
Incomplete string token.
At line:1 char:4
+ &{` <<<<
+ CategoryInfo : ParserError: (`:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : IncompleteString
'$process' is not recognized as an internal or external command,
operable program or batch file.
'$process.WaitForExit' is not recognized as an internal or external command,
operable program or batch file.
'}"' is not recognized as an internal or external command,
operable program or batch file.
Может ли кто-нибудь сказать мне, что я делаю неправильно?
РЕШЕНИЕ:
powershell -noprofile -command "&{"^
"$process = start-process powershell -ArgumentList '-noprofile -noexit -file C:\Dev\Powershell\Sandbox.ps1' -verb RunAs -PassThru;"^
"$process.WaitForExit();"^
"}"
Это приводит к следующему:. «Missing закрытия '}' в блок операторов В строке : 1 char: 4 + & {^ <<<< + CategoryInfo: ParserError: (CloseBraceToken: TokenId) [], ParentContainsErrorRecord Исключение + FullyQualifiedErrorId: MissingEndCurlyBrace «$ process» не распознается как внутренняя или внешняя команда, операционная программа или командный файл. " –
Попробуйте добавить пробел в начале следующих строк. – marapet
Не работает, по-прежнему такая же ошибка. :/ –