<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Huddled Masses &#187; SourceCode</title>
	<atom:link href="http://huddledmasses.org/tag/sourcecode/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Writing Cmdlets for the PowerShell Pipeline</title>
		<link>http://huddledmasses.org/writing-cmdlets-for-the-powershell-pipeline/</link>
		<comments>http://huddledmasses.org/writing-cmdlets-for-the-powershell-pipeline/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 05:25:57 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Cmdlet]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[My Software]]></category>
		<category><![CDATA[Pipeline]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SourceCode]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/writing-cmdlets-for-the-powershell-pipeline/</guid>
		<description><![CDATA[In a continuation of what is, sadly, becoming a series on how the PowerShell Pipeline works &#8230; Karl Prosser brought to my attention that certain powershell commands which have an -InputObject parameter don&#8217;t actually work when you pass something into it &#8230; so I thought I should create a cmdlet to show you how to [...]]]></description>
			<content:encoded><![CDATA[	<p>In a continuation of what is, <em>sadly</em>, becoming a series on how the <a href="/tag/Pipeline">PowerShell Pipeline</a> works &#8230; <a href="http://powershelllive.com/members/karl.aspx">Karl Prosser</a> brought to my attention that certain powershell commands which have an -InputObject parameter don&#8217;t actually work when you pass something into it &#8230; so I thought I should create a cmdlet to show you how to correctly handle the <code>InputObject</code> parameter with the <code>ValueFromPipeline</code> set so you can pass the input in either way.  </p>

	<h4>To demonstrate the problem, try this:</h4>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$a</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;A&quot;</span>,<span style="color: #009900;">&quot;B&quot;</span>,<span style="color: #009900;">&quot;A&quot;</span>,<span style="color: #009900;">&quot;C&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$a</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> <span style="color: #000066;">-First</span> <span style="color: #cc66cc;">3</span> <span style="color: #000066;">-Unique</span><br />
<span style="color: #660033;">Select</span> <span style="color: #000066;">-First</span> <span style="color: #cc66cc;">3</span> <span style="color: #000066;">-Unique</span> <span style="color: #000066;">-InputObject</span> <span style="color: #660033; font-weight: bold;">$a</span> </div>

	<p>This should expose two weirdnesses about how the <code>Select-Object</code> cmdlet works: </p>

	<ol>
		<li>The -First parameter affects the input before the -Unique parameter does.</li>
	</ol>
	<ol>
		<li>When you pass the input in via -InputObject, the whole array is treated as a single object, and the command basically doesn&#8217;t do anything.</li>
	</ol>

	<p>The big problem with this behavior is that there&#8217;s essentially no hint that you&#8217;ve done something wrong &#8212; there&#8217;s actually no way to make Select-Object work properly <strong>except</strong> by passing the objects in via the pipeline.  The bigger problem is that it would have been simple for the Microsoft team to catch this and alert you, but they didn&#8217;t &#8212; so you probably won&#8217;t even notice there&#8217;s a problem until you run it on a trivial data set like my example.  The even <strong>bigger problem</strong> is that it doesn&#8217;t just affect Select-Object (try it with Where-Object, just for instance). <span id="more-458"></span></p>

	<h4>The simplest fix</h4>

	<p>When this came up in the #PowerShell <span class="caps">IRC</span> channel <a href="http://nivot.org">Oisin</a> initially defended this as an unavoidable side effect of the way the cmdlet system works. However, after playing with the idea for a bit, we found it&#8217;s actually trivial to stop, although I found it hard to explain without actually <a href="/wordpress/wp-content/uploads/2007/11/testpipelinecommand1.cs">demonstrating an alternative</a>. The simplest possible alternative is just to throw an exception if the value is passed in as an argument instead of via the pipeline. That would preserve the same level of functionality you have now &#8212; but cause an error in those cases where it wouldn&#8217;t work anyway.</p>

	<div class="csharp code csharp" style="font-family:monospace;"><br />
<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> BeginProcessing<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_input <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">throw</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ArgumentException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;You must pass InputObject via the pipeline!&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">BeginProcessing</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #000000;">&#125;</span></div>

	<h4>A better way to handle input</h4>

	<p>Of course, you can do better than that  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> .  So, I hereby present the first version of my <a href="/wordpress/wp-content/uploads/2007/11/testpipelinecommand2.cs">PowerShell Pipeline Template Cmdlet</a>.  It&#8217;s pretty simple really (once you get past all the cmdlet overhead): basically, you check in the <code>BeginProcess()</code> method to see if the <code>InputObject</code> parameter has been set, and set an alternate private variable. Then, in the <code>ProcessRecord()</code> method, we have two alternate computation paths: the normal path, and a second path for when the collection is passed in as an argument.  In that case, you recurse and call the ProcessRecord method once for each item in the collection.</p>

	<p>I&#8217;m sure some of you will have some improvements you can make, feel free to continue the development on the PowerShell Central <a href="http://powershellcentral.com/scripts/43">scripts page</a> or by sending feedback in the form below, but for now, here&#8217;s <a href="/wordpress/wp-content/uploads/2007/11/testpipelinecmdlet.7z">the Test-Pipeline Cmdlet Binary</a> and the <a href="/wordpress/wp-content/uploads/2007/11/testpipelinecommand2.cs">source code</a>.</p>

	<h4>The Code</h4>

	<div class="csharp code csharp" style="font-family:monospace;"><br />
<span style="color: #008080; font-style: italic;">// An improvement! Now we accept a single object (like Select-Object does)</span><br />
<span style="color: #008080; font-style: italic;">// But, unlike Select-Object, if an array is passed into the argument -InputObject </span><br />
<span style="color: #008080; font-style: italic;">// we still manage to process each item in the array, as we would in the pipeline</span><br />
<span style="color: #008080; font-style: italic;">//</span><br />
<span style="color: #008080; font-style: italic;">// Try it out: &nbsp; &quot;a&quot;,&quot;b&quot;,&quot;c&quot;| Test-Pipeline -verbose</span><br />
<span style="color: #008080; font-style: italic;">// Versus this: &nbsp;Test-Pipeline -verbose -input @(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;)</span><br />
<span style="color: #008080; font-style: italic;">//</span><br />
<span style="color: #008080; font-style: italic;">// If you don't set the -verbose flag, you shouldn't be able to tell them apart</span><br />
<span style="color: #008080; font-style: italic;">// The first way, the &quot;1&quot; invocation hits ProcessRecord for &quot;a&quot; </span><br />
<span style="color: #008080; font-style: italic;">// ... before the &quot;2&quot; invocation hits BeginProcessing()</span><br />
<span style="color: #008080; font-style: italic;">//</span><br />
<span style="color: #008080; font-style: italic;">// Version History</span><br />
<span style="color: #008080; font-style: italic;">// &nbsp; &nbsp;1.0 Just throws an exception</span><br />
<span style="color: #008080; font-style: italic;">// &nbsp; &nbsp;2.0 Finds a way to enumerate ProcessRecord from BeginProcessing</span><br />
<span style="color: #008080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp;There is still a slight difference, which you can see if you test these:</span><br />
<span style="color: #008080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Test-Pipeline 1 -input @(&quot;a&quot;,&quot;b&quot;,&quot;c&quot;) -verbose | Test-Pipeline 2 -verbose</span><br />
<span style="color: #008080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;a&quot;,&quot;b&quot;,&quot;c&quot; | Test-Pipeline 1 -verbose | Test-Pipeline 2 -verbose</span><br />
<span style="color: #008080; font-style: italic;">// &nbsp; &nbsp;2.3 Recursed from inside ProcessRecord instead of BeginProcessing</span><br />
<span style="color: #008080; font-style: italic;">// &nbsp; &nbsp; &nbsp; &nbsp;Makes the execution look identical in the test case from 2.0</span><br />
<span style="color: #008080; font-style: italic;">////////////////////////////////////////////////////////////////////////////////</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Management.Automation</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #0600FF;">namespace</span> Huddled.<span style="color: #0000FF;">TestSnapin</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Cmdlet<span style="color: #000000;">&#40;</span>VerbsDiagnostic.<span style="color: #0000FF;">Test</span>, <span style="color: #666666;">&quot;Pipeline&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> TestPipelineCommand <span style="color: #008000;">:</span> Cmdlet<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region Parameters</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// This is just a name parameter for decorating test cases :)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Mandatory <span style="color: #008000;">=</span> <span style="color: #0600FF;">false</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ValueFromPipelineByPropertyName <span style="color: #008000;">=</span> <span style="color: #0600FF;">false</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HelpMessage <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;A Name for Verbose output&quot;</span><span style="color: #000000;">&#41;</span>, ValidateNotNullOrEmpty<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Name<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _name<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set <span style="color: #000000;">&#123;</span> _name <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> _name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;TestPipeline&quot;</span><span style="color: #008000;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Mandatory <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ValueFromPipeline <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HelpMessage <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Help Text&quot;</span><span style="color: #000000;">&#41;</span>, ValidateNotNullOrEmpty<span style="color: #000000;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span> InputObject<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _input<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set <span style="color: #000000;">&#123;</span> _input <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">object</span> _input<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> _isArgument <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> BeginProcessing<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteVerbose<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Begin Processing {0}&quot;</span>, Name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_input <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> _input <a href="http://www.google.com/search?q=is+msdn.microsoft.com"><span style="color: #008000;">is</span></a> ICollection<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _isArgument <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StringBuilder output <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;There's input: &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> _in <span style="color: #0600FF;">in</span> <span style="color: #000000;">&#40;</span>ICollection<span style="color: #000000;">&#41;</span>_input<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; output.<span style="color: #0000FF;">AppendFormat</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{0}, &quot;</span>, _in<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteVerbose<span style="color: #000000;">&#40;</span>output.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">BeginProcessing</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ProcessRecord<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>_isArgument<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// This is the normal ProcessRecord code</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteVerbose<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Process: {0}&quot;</span>, _input<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteObject<span style="color: #000000;">&#40;</span>_input<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// This is what we have to do unwrap -InputObject as Arg</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ICollection _collection <span style="color: #008000;">=</span> _input<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _isArgument <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// unset isCollection before recursing</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> _in <span style="color: #0600FF;">in</span> <span style="color: #000000;">&#40;</span>ICollection<span style="color: #000000;">&#41;</span>_collection<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InputObject <span style="color: #008000;">=</span> _in<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ProcessRecord<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> EndProcessing<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WriteVerbose<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;End Processing {0}&quot;</span>, Name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">EndProcessing</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/writing-cmdlets-for-the-powershell-pipeline/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

