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.
Let's practice! Open a PowerShell console session, type exit , and press the Enter key. The PowerShell console will immediately close. This keyword can also exit a script rather than the console session.
Using PowerShell newline in Command To add newline in the PowerShell script command, use the` (backtick) character at the end of each line to break the command into multiple lines.
In the PowerShell console you use the Ctrl+Break key combination to break into the debugger.
% is an alias for the ForEach-Object cmdlet. An alias is just another name by which you can reference a cmdlet or function.
And right after I asked, I figured it out... Hitting Enter twice made it happen :)
If you continue to get >> prompts after pressing enter twice, check your script for unterminated strings, i.e., unpaired quotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With