Converting the FileSystemObject's ReadLine Method

Definition: Reads a single line from a text file.


Get-Content C:\Scripts\test.txt -totalcount 1

Get-Content returns lines of text from a file as an array, which means you can also read all the contents then access individual lines by accessing the associated array item. For example, this code returns the third line (array item 2) from the file:

(Get-Content C:\Scripts\test.txt)[2]

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