Powershell

How to Break Lines in PowerShell?

PowerShell is a CLI (Command Line Interface) tool used to carry out administrative tasks. Moreover, PowerShell is used for scripting purposes. It also provides some other features, such as adding or breaking lines. Normally, PowerShell gives an output in a single line, but the output can be displayed in multiple lines by breaking them. Utilizing it helps the output to look neat and clean.

This write-up aims to provide a method to break lines in PowerShell.

How to Break Lines in PowerShell?

The PowerShell output can be broken down into multiple lines using the new line function. The output displayed after using the new line function looks like the multiple results saved in a single file.

The new line function is used in PowerShell by utilizing the ā€œ`nā€ character. This character breaks the sequence and creates a new line.

For further demonstration, look at the given examples.

Example 1: Use ā€œ`nā€ to Break Into Two Lines in PowerShell

This example will demonstrate the breaking of lines in PowerShell using the ā€œ`nā€ keyword:

> write-output "Hello `nWorld"

 
In the above command:

    • First, we have utilized the ā€œwrite-outputā€ command for writing out the text to the console.
    • After that, the ā€œ`nā€ character is used once to break the statement into two lines:

 

It can be observed that the statement ā€œHello Worldā€ is now split into two separate lines.

Example 2: Use ā€œ`nā€ to Break Into Multiple Lines in PowerShell

This example will show you how to break into multiple lines using the ā€œ`nā€ character more than once in PowerShell:

> write-output "It `nis `nBeautiful `nCat"

 

The output text has been broken down into multiple lines.

Conclusion

To break lines in PowerShell, the new line function is used, and it is represented as a ā€œ`nā€ character. To utilize it, simply add the ā€œ`nā€ character in the input text. The text after the ā€œ`nā€ keyword will be displayed in the new line. Moreover, it can be utilized more than once to break into multiple lines. This write-up discussed the method for breaking lines in PowerShell.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.