que tiene una secuencia de comandos por lotes que se parece a esto:Powershell -Command al borde múltiple
Prueba.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();}"
me gustaría dividir el código dentro de la "& {...} "sobre líneas múltiples para legibilidad.
This Post dice que el uso de un acento grave de arrastre debe hacer el truco, pero cuando escribo:
powershell -noprofile -command "&{`
$process = start-process powershell -ArgumentList '-noprofile -noexit -file GetTools.ps1' -verb RunAs -PassThru;`
$process.WaitForExit();`
}"
... es decir, termino cada línea con un acento grave se arrastra, entonces me sale el siguiente error :
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.
¿Alguien me puede decir lo que estoy haciendo mal?
SOLUCIÓN:
powershell -noprofile -command "&{"^
"$process = start-process powershell -ArgumentList '-noprofile -noexit -file C:\Dev\Powershell\Sandbox.ps1' -verb RunAs -PassThru;"^
"$process.WaitForExit();"^
"}"
que se traduce en:. "Cierre Missing '}' en el bloque de instrucciones En línea : 1 char: 4 + & {^ <<<< + CategoryInfo: ParserError: (CloseBraceToken: TokenId) [], ParentContainsErrorRecord Excepción + FullyQualifiedErrorId: MissingEndCurlyBrace '$ process' no se reconoce como un comando interno o externo, programa operable o archivo por lotes. " –
Intenta agregar un espacio al comienzo de las siguientes líneas. – marapet
No funcionó, igual recibió el mismo error. :/ –