2

I have to execute two commands (including a PowerShell one) in new console window. Let me explain:

I am able to execute a PowerShell command from cmd in a new console window (I can specify the command inside quotes):

start /W cmd /K powershell -command "&{Write-Host 'Hello World!';}" 

And I can execute two commands (I can write both commands in quotes):

start /W cmd /K "echo Hello && echo World" 

But how can I do it together (execute two commands, one of them PowerShell)? I would like to do it without any .bat or .ps script.

I tried something like following (and some variations with escaping character), but I cannot deal with this quotes issue (there are quotes for joining two commands and inside quotes for PowerShell command).

start /W cmd /K "echo Hello && powershell -command "&{Write-Host 'Hello World!';}"" 

1 Answer 1

2

You need to escape & in powershell's ScriptBlock for cmd:

start /W cmd /K "echo Hello && powershell -command "^&{Write-Host 'Hello World!';}""

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, so the problem was with &, not quotes... It works, thanks for help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.