Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting the FileSystemObject's Write Method

Windows PowerShell

Definition: Writes a string (without 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"

Note that in PowerShell a newline character is always appended to the end of the line.

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

© 2016 Microsoft