Sumeet Singh
Sumeet Singh

Reputation: 121

Adding multiple line at the end of the file using powershell

I am trying to add multiple line at the end of the file using powershell. for example : The file is already present and have some content in it.

abc.txt

abc
def
ghi
jkl
mno
pqr

So abc.txt file looks like something I have mention above. Now i am trying to add below content at the end of the file and on new line.

qwe
asd
zxc
vbn

The final output will be - abc.txt

abc
def
ghi
jkl
mno
pqr
qwe
asd
zxc
vbn

As i am a newbiw i tried adding one line in a file which has been perform successfully but no idea of adding multiple line.

 Add-Content "./sample3.txt" "This is the last line `n"

Upvotes: 9

Views: 17488

Answers (1)

Venkataraman R
Venkataraman R

Reputation: 13009

You can add content as given below. Read more on here string

$contentToAdd = @"
qwe
asd
zxc
vbn
"@

 Add-Content "C:\dev\abc.txt" $contentToAdd

Upvotes: 19

Related Questions