user358485 user358485 - 8 months ago 53
PowerShell Question

script to make content entry into a text file

How to include some "text" into a .txt format file without opening the same via a script on windows?


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 use Out-File also.

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