Tutorial by Examples

function earlyexit { "Hello" return "World" } "Hello" will be placed in the output pipeline, "World" will not
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...
Inspired by PowerShell: Function doesn't have proper return value function bar { [System.Collections.ArrayList]$MyVariable = @() $MyVariable.Add("a") | Out-Null $MyVariable.Add("b") | Out-Null $MyVariable } The Out-Null is necessary because the .NET ArrayLis...
(paraphrased from about_return) The following methods will have the same values on the pipeline function foo { $a = "Hello" return $a } function bar { $a = "Hello" $a return } function quux { $a = "Hello" $a }
A function returns everything that is not captured by something else. If u use the return keyword, every statement after the return line will not be executed! Like this: Function Test-Function { Param ( [switch]$ExceptionalReturn ) "Start" if($Exceptio...

Page 1 of 1