X

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 is an example of how to use the add-content PowerShell cmdlet to append text to a file on Windows. We'll also explain 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

Take a look here if you need to create a directory first.

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 websites.
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings