title: Piping into objects/properties/methods in PowerShell
body: <p>In PowerShell, you can pipe into Cmdlets and into scripted functions. But is it possible to pipe into objects, properties, or member functions?</p>
  
  <p>For example, if I have a database connection object <code>$dbCon</code>, I want to be able to so something like this:</p>
  
  <pre><code>$dbCon.GetSomeRecords() | &lt;code-to-manipulate-those-records | $dbCon.WriteBackRecords()
  </code></pre>
  
  <p>I know the same functionality can be achieved with <code>Foreach-Object</code> or with a Cmdlet that gets the object as an argument - the reason I want to pipe directly to the object or to it's members is to achieve elegance and to keep the OOP style(using an object's method instead of sending the object as an argument)</p>
  
  <p>Is it possible?</p>
  
  <hr>
  
  <p><strong>EDIT:</strong></p>
  
  <p>It looks like people don't understand my question, so I need to clarify it:</p>
  
  <p>PowerShell can pipe to normal functions. I can Write:</p>
  
  
  
  <pre><code>function ScriptedFunction
  {
      $input|foreach{"Got "+$_}
  }
  1,2,3|ScriptedFunction
  </code></pre>
  
  <p>And get<br>
  <code>
  Got 1<br>
  Got 2<br>
  Got 3</code><br>
  As the result. But when I try to use that technique with a scripted method:</p>
  
  
  
  <pre><code>$object=New-Object System.Object
  $object|Add-Member -MemberType ScriptMethod -Name ScriptedMethod -Value {$input|foreach{"Got "+$_}}
  1,2,3|$object.ScriptedMethod
  </code></pre>
  
  <p>I get an error message: <code>Expressions are only allowed as the first element of a pipeline.</code>(adding () does not help BTW). What I'm looking for is a way to make that command work the same way it works with global functions.</p>