foreach($line in Get-Content -Path C:\input.txt) { if ($line -eq "error"){ Write-Output $line } }