title: Powershell: conditional flag based on a local variable
body: <p>There is a variable in my PowerShell script called <code>$IncludeSubfolders</code> (either <code>0</code> or <code>1</code>)</p>
  
  <p>Depending on its value, I would like to call <code>Get-ChildItem</code> method either with or without the <code>-Recurse</code> option.</p>
  
  <p>Currently, my code looks like this:</p>
  
  <pre><code>if($IncludeSubfolders) {
      $Files = Get-ChildItem $RootPath -Name $FileMask -Recurse
  } else {
      $Files = Get-ChildItem $RootPath -Name $FileMask
  }
  </code></pre>
  
  <p>I would like to avoid this branching and just have a single line of code calling <code>Get-ChildItem</code> with <code>-Recurse</code> flag if <code>$IncludeSubfolders</code> is <code>1</code> or without it if it is <code>0</code>.</p>
  
  <p>Is this achievable? How?</p>
  
  <p>Powershell version 5.0.10586.117</p>