I’m processing tab-separated text file (ANSI) in PowerShell 1.0, and for some reason I can’t split text in the file into multiple fields using the split function. The code below always returns 1 although there are five values separated by tab in each line of the file.
$f = get-content ‘users.txt’
foreach ($line in $f)
{
$fields = $line.split('\t')
$fields.count | Out-Host
}
I tested split with other separators like pipe, comma and it worked without problems.
You’re using the wrong escape character for the tab. Try this instead: