title: Get-ChildItem recurse as a parameter in PowerShell
body: <p>I am looking to create a function that could toggle the ability to recurse in <a href="http://technet.microsoft.com/en-us/scriptcenter/dd772285.aspx" rel="noreferrer">cmdlet</a> <a href="http://technet.microsoft.com/en-us/library/ee176841.aspx" rel="noreferrer">Get-ChildItem</a>.</p>
  
  <p>As a very basic example:</p>
  
  <pre><code>...
  
  param 
  (   
      [string] $sourceDirectory = ".",
      [string] $fileTypeFilter = "*.log",
      [boolean] $recurse = $true
  )
  
  Get-ChildItem $sourceDirectory -recurse -filter $fileTypeFilter | 
  
  ...
  </code></pre>
  
  <p>How does one conditionally add the <code>-recurse</code> flag to Get-ChildItem without having to resort to some if/else statement?</p>
  
  <p>I thought perhaps one could just substitute the <code>-recurse</code> in the Get-ChildItem statement with a <code>$recurseText</code> parameter (set to "-recurse" if $recurse were true), but that does not seem to work.</p>