Check first character of each line for a specific value in PowerShell

Use:

$Fours = @()
$Sixes = @()
GC $file|%{
    Switch($_){
        {$_.StartsWith("4")}{$Fours+=$_}
        {$_.StartsWith("6")}{$Sixes+=$_}
    }
}

Something like this would probably work.

$sixArray = @()
$fourArray = @()

$file = Get-Content .\ThisFile.txt
$file | foreach { 
    if ($_.StartsWith("6"))
    {
        $sixArray += $_
    }

    elseif($_.StartsWith("4"))
    {
        $fourArray += $_
    }
}

If you're running V4:

$fourArray,$sixArray = 
((get-content $file) -match '^4|6').where({$_.startswith('4')},'Split')