Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Converting the FileSystemObject's WriteLine Method


Windows PowerShell


Definition: Writes a string (followed by a newline character) to a text file.

WriteLine


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.


See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.