Converting the FileSystemObject's WriteBlankLines Method

Definition: Adds a specified number of blank lines (newline characters) to a text file.


To add a blank line in PowerShell, use either of these commands:

Add-Content c:\scripts\test2.txt -value ""


Add-Content c:\scripts\test2.txt -value "`n"

You can use the latter to add more than one blank line; this example adds three blank lines:

Add-Content c:\scripts\test2.txt -value "`n`n`n"

To add a lot of blank lines, you could simply put the command in a loop, looping through once for each blank line you want to add. This loop adds 5 blank lines:

for($i = 1; $i -lt 6; $i++)
    Add-Content c:\scripts\test2.txt -value "`n"

See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page