top of page

PowerShell script to add text to a file

You can easily add text to the end of a text file using the PowerShell Add-Content command. So if you have text file like this which has only one line of text:



. . .and you want to add four new lines of text, you can write a PowerShell script like this:


Add-Content "C:\foofolder\test\test\NL East.txt" "`nPhiladelphia Phillies"

Add-Content "C:\foofolder\test\test\NL East.txt" "Atlanta Braves"

Add-Content "C:\foofolder\test\test\NL East.txt" "Washington Nationals"

Add-Content "C:\foofolder\test\test\NL East.txt" "Florida Marlins"


Open Windows PowerShell ISE [everyone running Windows should have this preinstalled], and enter the script in the script pane, and then run the script by clicking the green play button.


Note that for the first new line, we need to indicate that a line break should be entered. This is done by using a backtick '`' and an 'n' as a reference. The backtick is not the same as an apostrophe. On most keyboards it will be at the top far left before the number keys, and below the tilde key. Adding a `n reference for each new line will lead to the new entries being double spaced.



Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page