Passing a list of commands inside a script block ({ ... }) to powershell -Command for execution as-is is only supported from within PowerShell itself, as running powershell -h will tell you.
From outside of PowerShell, simply pass the commands as-is, but preferably inside double quotes, so as to prevent unintended up-front interpretation of the arguments by cmd.exe:
powershell -command "echo beep ; echo beep"
Note, however, that cmd.exe-style environment-variable references (e.g., %USER%) are still expanded up front.
Alternatively, you could pass a script block (string)[1]
preceded by &, the call operator to ensure the script block's execution, but that is only necessary if you want to pass arguments to the script block:
powershell -command "& { echo $Args[0]; echo $Args[0] } beep"
beep is passed as the 1st argument, which the script block references as $Args[0].
As an aside: In PowerShell echo is an alias of Write-Output, which writes to the success output stream; the output from any command or expression that isn't captured or redirected implicitly goes to the output stream, so that use of echo / Write-Output is generally unnecessary:
powershell -command "& { $Args[0]; $Args[0] } beep"
[1] From inside PowerShell, passing a script block to powershell -command causes the calling PowerShell session to recognize it and to treat the enclosed commands as the ones to pass to the new session to execute.
From outside of PowerShell, {...} is a string passed to the new session,
and it is the new session that then parses that string as PowerShell code. Evaluating a script block by itself, without explicit invocation via & (or .), simply outputs the literal contents of the script block, which explains your output; you can verify this behavior by submitting
{ echo beep; echo beep } at the PowerShell prompt.
& { ... }in order to invoke code passed to PowerShell's CLI via the-command(-c) parameter - just use...directly. Older versions of the CLI documentation erroneously suggested that& { ... }is required, but this has since been corrected - see this GitHub docs issue.