Converting the FileSystemObject's WriteLine Method
Definition: Writes a string (followed by a newline character) to a text file.
In VBScript, the string either replaces all existing content or is appended to the end of the file, depending on whether the file was opened ForWriting or ForAppending.
In PowerShell, content is appended using the Add-Content cmdlet:
Add-Content C:\Scripts\test.txt -value "New Content"
If you want to overwrite existing content, first call the Clear-Content cmdlet:
Clear-Content C:\Scripts\test.txt Add-Content C:\Scripts\test.txt -value "New Content"
Another option is the Out-File cmdlet:
Out-File C:\Scripts\test.txt -input "New Content" Out-File C:\Scripts\test.txt -input "New Content" -append
The first line overwrites and existing contents in the file with the contents specified by the -input parameter (in this case “New Content”). In the second line, we’ve added the -append parameter to append the new content rather than overwrite the file.