title: Exit a PowerShell function but continue the script
body: <p>This might seem like a very very stupid question, but I can't really figure it out. I'm trying to have the function stop when it finds its first hit (match) and then continue with the rest of the script.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>Function Get-Foo {
      [CmdLetBinding()]
      Param ()
  
      1..6 | ForEach-Object {
          Write-Verbose $_
          if ($_ -eq 3) {
              Write-Output 'We found it'
  
              # break : Stops the execution of the function but doesn't execute the rest of the script
              # exit : Same as break
              # continue : Same as break
              # return : Executes the complete loop and the rest of the script
          }
          elseif ($_ -eq 5) {
              Write-Output 'We found it'
          }
      }
  }
  
  Get-Foo -Verbose
  
  Write-Output 'The script continues here'
  </code></pre>
  
  <p><strong>Desired result:</strong></p>
  
  <pre><code>VERBOSE: 1
  VERBOSE: 2
  VERBOSE: 3
  We found it
  The script continues here
  </code></pre>
  
  <p>I've tried using <code>break</code>, <code>exit</code>, <code>continue</code> and <code>return</code> but  none of these get me the desired result. Thank you for your help.</p>