Is it possible to split a PowerShell command line over multiple lines?
In Visual Basic I can use the underscore (_) to continue the command in the next line.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use a space followed by the grave accent (backtick):
However, this is only ever necessary in such cases as shown above. Usually you get automatic line continuation when a command cannot syntactically be complete at that point. This includes starting a new pipeline element:
will work without problems since after the
|the command cannot be complete since it’s missing another pipeline element. Also opening curly braces or any other kind of parentheses will allow line continuation directly:Similar to the
|a comma will also work in some contexts:Keep in mind, though, similar to JavaScript’s Automatic Semicolon Insertion, there are some things that are similarly broken because the line break occurs at a point where it is preceded by a valid statement:
will not work.
Finally, strings (in all varieties) may also extend beyond a single line:
They include the line breaks within the string, then.