I'd like to pass a string variable into a running a command in a new powershell window.
$word = "bird"
start PowerShell { echo $word; pause }
How do I do this?
Somehow it works better without the curly brackets, and with double quotes to get the variable interpreted. I guess the script block gets converted to a string by start-process. "Powershell -Command" is implied.
start powershell "echo $word; pause"
Or this works with the call operator:
start PowerShell "& { echo $word; pause }"
"Powershell -?" sort of touches on this.
-Command
...
If the value of Command is a script block, the script block must be enclosed
in braces ({}). You can specify a script block only when running PowerShell.exe
in Windows PowerShell.
...
If the value of Command is a string, Command must be the last parameter
in the command , because any characters typed after the command are
interpreted as the command arguments.
To write a string that runs a Windows PowerShell command, use the format:
"& {<command>}"
where the quotation marks indicate a string and the invoke operator (&)
causes the command to be executed.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.