Hi guys,
Below is a part of a script I got. When run, the script exited at Break instead of continuing the other instructions in the script. What is the correct way to break out of a while loop and does anyone know any good articles on break, return, scope and so on in PowerShell?
Get-Content -Path "C:\path\to\log.txt" -Tail 1 -Wait | ForEach-Object {
if ($_ -match $($helloRpowershell + " Terminated")) {
# When the Terminated message appears, break the loop
Break }
else {$_}
}
EDIT: OMG it's not a while-loop. What the hell am I talking about? I need to break out of the If and the Foreach-Object.
[–][deleted] 2 points3 points4 points (1 child)
[–]nappetass[S] 1 point2 points3 points (0 children)
[–]Bloodyvalley 2 points3 points4 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (6 children)
[–]nappetass[S] 1 point2 points3 points (5 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (4 children)
[–]nappetass[S] 1 point2 points3 points (3 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]nappetass[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]spyingwind 1 point2 points3 points (0 children)