Converting the FileSystemObject's AtEndOfStream Property

Definition: When reading through a text file one line at a time, returns True when you reach the end of the file.


The Get-Content cmdlet reads each line in as an array, which means the end of the file is the Length of the array.

Here we use the Get-Content cmdlet to retrieve the contents of the file test.txt. We then set up a for loop to loop through the lines in this content, up to the number of lines in the file ($a.length), echoing each line each time through the loop:

$a = Get-Content c:\scripts\test.txt
for ($i = 0; $i -lt $a.length; $i++)

You can also do this with a foreach loop:

$a = Get-Content c:\scripts\test.txt
foreach($l in $a){$l}

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