You can use the PowerShell add-content cmdlet to append data to a text file. Here are an example and the command-line options that you can use.

Powershell add-content example

Step 1. Open PowerShell with elevated privileges

Step 2. Execute the following command, (change the file path)

Add-Content c:\scripts\test.txt "The End"

By default, the data is appended after the last character. If you want to append the data on a new line in the text document, use 'n. There are some other special characters that can be used with the add-content cmdlet.

Here are some other special characters that can be used with the add-content cmdlet.

  • `0 -- Null
  • `a -- Alert
  • `b -- Backspace
  • `n -- New line
  • `r -- Carriage return
  • `t -- Horizontal tab
  • `' -- Single quote
  • `" -- Double quote
How to Append Data to a Text File Using PowerShell
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.

One thought on “How to Append Data to a Text File Using PowerShell

  • Avatar
    October 9, 2019 at 1:52 pm
    Permalink

    Sometimes if i fill a Variable using `n — New line “line for line” and use the Add-Content the `n — New line is being ignored.

    the only solution so far is writing one line after the other into the file Add-Content seems to have its own “new line” function used this way.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*