Gotcha Return in the pipeline

suggest change
get-childitem | foreach-object { if ($_.IsReadOnly) { return } }

ForEach-Object and Where-Object run a script block for each object. return in that script block only moves on to the next pipeline object. It does not stop the pipeline. break is not a safe substitute: if there is no enclosing loop, it can stop the rest of the script. Prefer Where-Object to filter, or a foreach statement when you need break. The break example below can exit more than the pipeline:

get-childitem | foreach-object { if ($_.IsReadOnly) { break } }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents