Add-Content – append to specific line


I want to add text into specific line of txt file. I can’t find any solution on internet.

This code adds text in further line (I want for example second line):


If you want to add text to the end of a specific line, you can do it like this

If you want to replace the text instead of adding, just remove the ‘+’ sign.
You do of course have to set the variables
$filePath, $textToAdd and $lineNumber first.


Add-Content – append to specific line by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply