title: how to use "if" statements inside pipeline
body: <p>I'm trying to use <code>if</code> inside a pipeline.</p>
  
  <p>I know that there is <code>where</code> (alias <code>?</code>) filter, but what if I want activate a filter only if a certain condition is satisfied?</p>
  
  <p>I mean, for example:</p>
  
  <pre>
  get-something | ? {$_.someone -eq 'somespecific'} | format-table
  </pre>
  
  <p>How to use <code>if</code> inside the pipeline to switch the filter on/off? Is it possible? Does it make sense?</p>
  
  <p>Thanks</p>
  
  <p><strong>EDITED to clarify</strong></p>
  
  <p>Without pipeline it would look like this:</p>
  
  <pre>
  if($filter) {
   get-something | ? {$_.someone -eq 'somespecific'}
  }
  else {
   get-something
  }
  </pre>
  
  <hr>
  
  <p><strong>EDIT after ANSWER's riknik</strong></p>
  
  <p>Silly example showing what I was looking for. You have a denormalized table of data stored on a variable <code>$data</code> and you want to perform a kind of "drill-down" data filtering:</p>
  
  <pre>
  function datafilter {
  param([switch]$ancestor,
      [switch]$parent,
      [switch]$child,
      [string]$myancestor,
      [string]$myparent,
      [string]$mychild,
      [array]$data=[])
  
  $data |
  ? { (!$ancestor) -or ($_.ancestor -match $myancestor) } |
  ? { (!$parent) -or ($_.parent -match $myparent) } |
  ? { (!$child) -or ($_.child -match $mychild) } |
  
  }
  </pre>
  
  <p>For example, if I want to filter by a specific parent only:</p>
  
  <p><code>datafilter -parent -myparent 'myparent' -data $mydata</code></p>
  
  <p>That's very elegant, performant and simple way to exploit <code>?</code>. Try to do the same using <code>if</code> and you will understand what I mean.</p>