Export (0) Print
Expand All
Expand Minimize

Converting the FileSystemObject's AtEndOfStream Property


Windows PowerShell


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

AtEndOfStream


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++)
{
    $a[$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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft