Это делает много предположений о содержании ваших файлов, поэтому, если не работает, вам может потребоваться обновить ваш вопрос с более подробной информацией:
$filename = "c:\src\scratch\text\log.txt";
# read an array containing each line of text from the file
# (there's a performance issue if the file has very many lines)
$lines = Get-Content -Path $filename;
# split each line into an array of words
# (another performance issue if the file is very large)
$records = $lines | % { @(, $_.Split(" ", [StringSplitOptions]::RemoveEmptyEntries)) };
# find the line where the second word is "REJECTED:"
# (assumes there's only ever exactly one "REJECTED" line)
# (arrays are zero-based so the first index is [0], and the second index is [1])
$rejected = $records | where-object { $_[1] -eq "REJECTED:" };
# convert the third word from that line into a number
$count = [int] $rejected[2];
write-host "rejected count = $count";
Вы можете сжать все это водин конвейер, если вы чувствуете себя смелым, но я оставил его расширенным, чтобы было легче увидеть, что происходит.
Когда я запускаю его с файлом примера, я получаю такой вывод:
rejected count = 1