Inserting blank lines in powershell console Inserting blank lines in powershell console powershell powershell

Inserting blank lines in powershell console


You can use `n to create a new line .

This is just a small example , if you want to modife the out put of the Get-Content command you should store the out put and then and the new line to line 10 for example then retrieve the out put.

write-host "This is an example"write-host "`n"write-host "just to show how to add a new line"

This example reads a file and when it get to line to in inserts a space.

$content = Get-Content C:\Dump\test.txtforeach ($line in $content){     if ($line.ReadCount -eq 2) { Write-Host "`n$line" }  Else{$line}}

This is the out put

Line 1Line 2Line 3Line 4Line 5Line 6Line 7


Best way to do blank lines for me is :

"" 

If you write that in script or console you get a blank line, just two double quotes.

If you want to create for example 3 new blank lines in one shot you could do :

"" ; "" ; "" 


write-host `n"hello"

the output is:

hello