-1

I need to process a text file in PowerShell. Some lines can have text like "DataItem 531", anywhere in the line. I can get those lines with this code:

$positions = New-Object -TypeName "System.Collections.ArrayList"
$regex = "\bDataItem\b \d+";

foreach($line in Get-Content $fileLog)
{
    if($line -match $regex)
    {
        $positions.Add($Matches[0].Split(' ')[1]) | Out-Null
    }
}

Is there a way to get the number (531) somehow directly, without using

$Matches[0].Split(' ')[1]
Alexey Titov
  • 221
  • 2
  • 9

0 Answers0