Add-Content is a versatile command if you need to add additional content to text files. For example, you can create log file entries like this:
Add-Content $home\logfile.txt ("{0:dd MM yyyy HH:mm:ss} New Entry" `
-f (Get-Date))
& "$home\logfile.txt"
But there is more. Use the -passThru parameter if you'd like to see what exactly Add-Content is adding. This way, Add-Content also sends the value to the console:
Add-Content $home\logfile.txt ("{0:dd MM yyyy HH:mm:ss} New Entry" `
-f (Get-Date)) -passThru
You should be aware that Add-Content happily accepts wildcards. The next line would add your log file entry to every single log file in your home folder (make sure there are some before you try):
Add-Content $home\*.log ("{0:dd MMM yyyy HH:mm:ss} New Entry" `
-f (Get-Date)) -whatIf
Posted
May 20 2009, 08:00 AM
by
ps1