Powershell Add-Content command adds the data to a file, this article explains how you can use it in your scripting code and add content to the file.
The PowerShell cmdlet add-content adds the content to the specified file, you can get the output of another file and add to it as input to another file, please below examples.
Syntax
add-content parameters.
Examples 1
Add-Content -Path c:\temp\config.txt -Value ‘all the best’
In the above examples the content “all the best” will be added to the file config.txt
Example2
Add-Content -Path .\logfile.log, .\logfile2.log -Value (Get-Date) -PassThru
In the above example, we have added the date to two files logfile and logfile2 at the end of the file.
We can read the file using the below command.
get-Content -Path .\logfile.log
Output,
Tuesday, April 14, 2020 10:44:06 PM
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply