21

This should be easy, but can't figure it out. How do I end a multi-line command in PowerShell? For example if I enter Get-ChildItem | and press enter then I get a >> prompt which I assume is to continue the command. But if I then enter foreach{Write-Host $_.name} and press enter I still get the >> prompt.

How do I say, I'm done, run this now? I thought it would happen when I wrote a complete command (not ending with a pipe or an unclosed bracket), but doesn't seem to. Also tried ending with a semi-colon, but that didn't help much.

Svish
  • 152,914
  • 173
  • 462
  • 620
  • 1
    You need to type an extra 'enter'... – CB. Nov 05 '12 at 09:20
  • 4
    Yup... \*facepalm\*... At least now if there are other stupid people like me they have a place to go :p – Svish Nov 05 '12 at 09:25
  • Possible duplicate of [How to enter a multi-line command?](http://stackoverflow.com/questions/3235850/how-to-enter-a-multi-line-command) – bahrep Nov 04 '16 at 16:32
  • @bahrep I think that is a completely different question. It is talking about splitting a command over multiple lines and all the answers are about using a backtick to escape the line end. – Martin Brown Sep 11 '20 at 19:29

3 Answers3

34

And right after I asked, I figured it out... Hitting Enter twice made it happen :)

Svish
  • 152,914
  • 173
  • 462
  • 620
19

If you continue to get >> prompts after pressing enter twice, check your script for unterminated strings, i.e., unpaired quotes.

Michael
  • 726
  • 7
  • 18
0

Also look for missing = sign between attribute and its value, this will give you >> prompts even after pressing enter twice.