Script to make content entry into a text file

user358485 picture user358485 · Feb 25, 2011 · Viewed 54.5k times · Source

How do I include some "text" into a .txt format file without opening the same via a script on Windows?

Answer

ravikanth picture ravikanth · Feb 25, 2011

I will give you an all PowerShell answer. You can use Add-Content or Set-Content cmdlets.

Set-Content overwrites the target file and Add-Content appends to the file.

Set-Content -Value "Test1" -Path C:\Scripts\Scratch\test.txt
Add-Content -Value "Test" -Path C:\Scripts\Scratch\test.txt

Or, you can also use Out-File.

"Test" | Out-File -FilePath C:\Scripts\Scratch\test.txt -Append