In this blog post, we will learn how to add new content to a file using PowerShell. In many use cases and situations, you might need to add a string or value to a TXT file without opening the file.
Add-Content
With the Add-content cmdlet, we can new content to an existing file without deleting or clearing the existing data that the file contains.
Code
Let’s take a look at the below code and example which I start with creating a new file and then using the add-content to add value to the file without clearing the data file.
New-Item test.txt Add-Content .\test.txt -Value "This is a test" cat .\test.txt This is a test
Go ahead and try and see how great the add-content cmdlet is and useful it can be in cases where a script or a process need to save data.
Processing…
Success! You're on the list.
Whoops! There was an error and we couldn't process your subscription. Please reload the page and try again.