Converting the FileSystemObject's OpenAsTextStream Method

Windows PowerShell

Definition: Open a file and reference the contents of the file.


The Get-Content cmdlet will retrieve the contents of a file:

Get-Content test.txt

The OpenAsTextStream method allows you to include an optional parameter specifying one of three formats of the file: system default, Unicode, or ASCII. In PowerShell, you get more choices by using the -encoding parameter of the Get-Content cmdlet: Unknown, String, Unicode, Byte, BigEndianUnicode, UTF8, UTF7, Ascii.

Get-Content test.txt -encoding String

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