Converting the FileSystemObject's SkipLine Method

Definition: When reading through a text file one line at a time (with the ReadLine method), preceding the call to ReadLine with a call to SkipLine will skip the next line, causing the next call to ReadLine to read the following line.

SkipLine

In VBScript this would typically happen in a loop that was reading through the file. In PowerShell, after retrieving the contents of the file with the Get-Content cmdlet, you can loop through and skip over the line you want to skip by skipping over that array item.

This example displays each line in the text file, skipping over the sixth line (array item 5):

$a = get-content c:\scripts\test.txt

for ($i = 0; $i -lt $a.length; $i++)
{
    if ($i -ne 5)
    {
        $a[$i]
    }
}

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