How do I get the Get-Content command to exit if a string match is found?
e.g. When "string to find" is matched in the followed file, how to exit the Get-Content command?
Get-Content file -wait | ? { $_ -match "string to find" }
How do I get the Get-Content command to exit if a string match is found?
e.g. When "string to find" is matched in the followed file, how to exit the Get-Content command?
Get-Content file -wait | ? { $_ -match "string to find" }
Break your problem into steps you can easily read and debug.
Perhaps something like this is a starting example:
One line:
$files = gci *.txt; foreach ($f in $files) {$s='XXX';"checking '$f'";if (select-string -Path $f -Pattern $s) { "file '$($f.Name)' contains '$s'"; break;}}
Expanded for readability, debug-ability, etc.:
$files = gci *.txt
foreach ($f in $files)
{
$s='XXX'
"checking '$f'"
if (select-string -Path $f -Pattern $s)
{
"file '$($f.Name)' contains '$s'"
break
}
}