title: Powershell: how to call a function from inside of a foreach loop?
body: <p>I'm testing if I can invoke a certain function based on the condition within a <code>foreach</code> loop:</p>
  <pre><code>$BROKER = $args[0]    
  $MARKETS = $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]
  
  
  foreach ($market in $MARKETS) {
      if ($market -like 'all') {
          &amp;AllMarkets
          break
      }
      else {
          &amp;CertainMarkets
      }
  }
  
  
  function AllMarkets {
      &quot;Checking all markets&quot;
  }
  
  
  function CertainMarkets {
      &quot;Checking certain markets&quot;
  }
  </code></pre>
  <p>When I run the script like this:</p>
  <pre><code>.\script.ps1 broker all
  </code></pre>
  <p>I get this error:</p>
  <pre><code>&amp; : The term 'AllMarkets' is not recognized as the name of a cmdlet, function, script file, or operable program
  </code></pre>
  <p>How to call these functions from inside the foreach loop?</p>