How to Append Data to a Text File Using PowerShell

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

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

  1. 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 Comment

*