How to stop Get-Content -wait after I find a particular line in the text file using powershell? Exit a pipeline on demand
问题 I am using this below script in Powershell (Version is 5.1): Get-Content -Path path\to\text\file\to\be\read.txt -Wait Now this continues to read even after the file is getting no update. How can I stop after I find particular line in the text file? Is there any other way to stop this on condition? 回答1: You can pipe the output and use foreach to check each line, if the line equals a certain string you can use break to stop the command: Get-Content path\to\text\file\to\be\read.txt -wait | % {$_