To split a long PowerShell command across multiple lines, end the line with the backtick character ` (the line-continuation character) and press Enter, then continue typing on the next line. PowerShell treats the joined lines as a single command. A cleaner alternative, and the one most people should use, is to break the command inside a natural delimiter: after a pipe |, after an opening parenthesis (, a comma in an array, or inside a hashtable or script block. PowerShell automatically knows those constructs are incomplete and keeps waiting for input, so no backtick is needed. The backtick is only truly required when you want to break at a point where PowerShell would otherwise consider the statement finished.

What You'll Need

  • Windows PowerShell 5.1 (built into Windows) or PowerShell 7.x. Both behave the same way for line continuation, so you can follow these steps in either.
  • A terminal: the Windows PowerShell console, PowerShell 7 console, Windows Terminal, or the integrated terminal in VS Code.
  • A long command you actually want to run. If you are just practising, any cmdlet works, such as Get-ChildItem.
  • Optional: a script editor (VS Code with the PowerShell extension) if the command is long enough that you want to save it as a script file instead of typing it.

Step-by-Step

  1. Decide where to break the line. The safest break points are immediately after a pipe |, after a comma in a list, inside an open parenthesis (, inside a hashtable @{, or inside a script block {. At these points PowerShell already expects more text, so it will not run anything early. Press Enter there and keep typing. No backtick is needed.
  2. Use the backtick when you must break anywhere else. Type a backtick (`, the key above Tab on most US keyboards, usually to the left of the 1 key), then press Enter. The next line is treated as part of the same command. Example of a long Get-ChildItem call:
    Get-ChildItem -Path C:\Logs `
        -Filter *.log `
        -Recurse `
        -ErrorAction SilentlyContinue
    Note that the backtick must be the very last character on the line. Anything after it, even a space, breaks the continuation and causes a syntax error.
  3. Indent the continuation lines. Start each continued line with spaces or a tab. The indentation is purely for readability and is ignored by PowerShell, but it makes a long command far easier to read and to edit later.
  4. Check the prompt before pressing Enter on the last line. If you used a pipe or an opening brace and the line is still incomplete, PowerShell changes the prompt to >> (the continuation prompt). When you type the closing bracket, brace or the final argument, the prompt returns to normal. Press Enter then to run the command.
  5. Prefer the natural break for readable commands. Compare the backtick version above with this pipe-based version, which needs no backticks at all:
    Get-ChildItem -Path C:\Logs |
        Where-Object { $_.Length -gt 1MB } |
        Sort-Object Length -Descending |
        Select-Object Name, Length -First 10
    This is the style most PowerShell guides and scripts use, because a trailing pipe is unambiguous and easy to spot.
  6. Build arrays and hashtables across lines. Arrays can span lines if the elements are separated by commas:
    $servers = @(
        'server01',
        'server02',
        'server03'
    )
    Hashtables split the same way, one key-value pair per line inside @{ }. Again, no backticks are needed inside the brackets.
  7. Edit before you run. If you made a mistake, the arrow-up key recalls the whole assembled command as one line in many hosts, but a multi-line entry may reappear as separate history entries depending on the console. To avoid surprises, type long commands in a script editor and run the saved .ps1 file, or highlight the block in the editor and use Run Selection in VS Code's PowerShell extension.
  8. Test the command safely first. For anything that changes data, such as Remove-Item or Stop-Service, add -WhatIf before the final Enter. That shows what the command would do without doing it.

Common Mistakes

  • A space after the backtick. This is the most common failure. The backtick must be the final character; a trailing space makes PowerShell treat the next line as a new command.
  • Breaking after a pipe in older hosts without realising the prompt changed. It works fine, but beginners see the >> prompt and think the shell has hung. It has not; it is waiting for the closing part of the pipeline.
  • Using the wrong quote character. Smart quotes from a word processor (curly ‘ and ’ or “ and ”) are not valid PowerShell quotes. Type straight quotes in the terminal or a plain-text editor.
  • Confusing the backtick with the apostrophe. The line-continuation character is the grave accent, not the single quote. They look similar on screen in some fonts.
  • Using backticks inside strings. A backtick inside double quotes is an escape character (for example, `n for a newline or `t for a tab), not a line continuation. Line continuation only applies to the code, not the contents of a quoted string.
  • Forgetting that syntax differs between the shell and a script file. A command that works when pasted into the console usually works in a script, but backticks are harder to preserve when copying from web pages, which may convert them or add spaces.

Tips

  • Favour pipes, parentheses, commas and braces over backticks. They survive copy-paste better and are easier to read.
  • Keep one parameter per line when a cmdlet has many arguments. It makes diffs and code review much easier.
  • Use Ctrl+Space for tab completion in the console; PowerShell 7 and recent 5.1 consoles support menu-style completion, which reduces the need for long typed commands.
  • If you regularly run the same long command, save it as a function in your profile ($PROFILE) or as a .ps1 script, then call it with a short name.
  • In VS Code and the PowerShell ISE, the editor handles multi-line commands natively, so you can press Enter freely rather than managing backticks.

Troubleshooting

If PowerShell shows a continuation prompt (>>) and will not run your command, it is waiting for the closing character or argument. Type the missing ), } or ], or press Ctrl+C to cancel the whole entry and start again.

If you get a command-not-found error or a parameter error on what should be a single command, the line probably did not join. Check for a space after a backtick, a smart quote, or a backtick that a web page turned into a different character. Re-type it by hand and confirm the backtick is immediately followed by Enter.

If a backtick command works in the console but fails in a script, open the file in a plain-text editor and look for trailing whitespace after the backticks. Some editors highlight trailing spaces, which makes this quick to spot.

If quotes or variables behave strangely, remember the difference between single and double quotes: double quotes expand variables and process escapes, single quotes take the text literally. This matters more once a command spans lines.

Frequently Asked Questions

Can I just press Enter in the middle of a command?

Only if the line is incomplete, such as after a pipe, comma or an opening bracket. Otherwise pressing Enter runs the command, and the rest of the text is treated as a new line.

What is the line-continuation character in PowerShell?

The backtick, also called the grave accent: `. It must be the last character on the line, with no space after it.

Is a backtick the same in PowerShell 7 as in Windows PowerShell 5.1?

Yes. Both versions use the backtick for line continuation and both accept multi-line input after pipes and brackets in the same way.

Why does my command show >> before I press Enter?

That is the continuation prompt. PowerShell is waiting for the rest of an unfinished statement. Complete it or press Ctrl+C to abandon it.

Can I use a backtick inside a quoted string to split it?

No. Inside double quotes the backtick is an escape character, so it produces a special character rather than a new line for the command. Split the string outside the quotes instead, or use here-strings for multi-line text.

Does the line continuation work when I paste a command from a browser?

Usually, but pasted text can contain trailing spaces or curly quotes. If a pasted multi-line command fails, paste it into Notepad first, check the backticks, then paste from there.