PowerShell Return behavior in PowerShell Gotcha! Return in the pipeline

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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

Pipeline cmdlets (ex: ForEach-Object, Where-Object, etc) operate on closures. The return here will only move to the next item on the pipeline, not exit processing. You can use break instead of return if you want to exit processing.

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


Got any PowerShell Question?