This tutorial will help the user to add a new line in PowerShell’s command output.
How to Add a Newline to the Output of Command in PowerShell?
These approaches can be utilized to add a new line in PowerShell:
Method 1: Use the “New line(`n)” Method to Add a New Line in PowerShell
Most usual way to add a new line to the PowerShell command output is by using the “`n”. For that reason, add it before the line you want to break or add a new line.
Example 1: Add a New Line
This example will add a new line in the output using the “`n” parameter:
Example 2: Add a Two-Line Break
This demonstration will add a two-line break by using the “`n” parameters two times consecutively:
Method 2: Use the “Carriage Return(`r)” Method to Add a New Line in PowerShell
The carriage return “`r” cmdlet when used with “`n” cmdlet can also add the new line. The carriage return “`r” helps move the cursor at the start of the line after breaking it.
In this illustration the “`r” will be used along with the “`n” parameter to add a new line in the output:
Method 3: Use the “Write-Host” Method to Add a New Line in PowerShell
Another method that is used to add single or multiple lines in the PowerShell output is by using the “Write-Host” cmdlet. It is also utilized to display multiple lines of code in the console.
This illustration will print multiple new lines in the PowerShell output console using the “Write-Output”:
write-host "It is a Linux OS."
write-host "It is a Linux Hint portal."
According to the above code, three “write-host” cmdlets have been added with some text inside.
That was all about adding a new line to command output in PowerShell.
The new line in the command output in PowerShell can be added by utilizing several methods. These methods include new line “`n”, carriage return “`r”, or the “Write-Host” cmdlet. This post has elaborated several methods with examples to add the new line to command output in the PowerShell console.