<?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; Programming</title>
	<atom:link href="http://huddledmasses.org/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Tue, 31 Aug 2010 04:13:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Random News Digest &#8230;</title>
		<link>http://huddledmasses.org/random-news-digest/</link>
		<comments>http://huddledmasses.org/random-news-digest/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 16:13:32 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[CodePlex]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=671</guid>
		<description><![CDATA[There&#8217;s fun stuff happening lately, so here&#8217;s a post full of tidbits you may have missed. Like: Codeplex has announced Subversion support. They will be running a server-side SvnBridge to allow access to all the projects so you can grab source more easily because it supports anonymous access. Amusingly, it&#8217;s actually easier to use than [...]]]></description>
			<content:encoded><![CDATA[	<p>There&#8217;s fun stuff happening lately, so here&#8217;s a post full of tidbits you may have missed.  Like:</p>

	<p>Codeplex has announced <a href="http://blogs.msdn.com/codeplex/archive/2008/09/14/codeplex-launches-support-for-tortoisesvn.aspx">Subversion support</a>.  They will be running a server-side SvnBridge to allow access to all the projects so you can grab source more easily because it supports anonymous access. Amusingly, it&#8217;s actually easier to use than <span class="caps">TFS</span>, all you need to know is the project name to get in. E.g.: <a href="https://PoshConsole.svn.codeplex.com/svn">https://PoshConsole.svn.codeplex.com/svn</a></p>

	<p>Clarius has just released of their <a href="http://www.t4editor.net/">T4 template editor</a> for Visual Studio.  There&#8217;s a free version, and a pro ($99) version. It&#8217;s excellent, and if you haven&#8217;t gotten into generating code using t4, what are you waiting for?</p>

	<p><a href="http://StackOverflow.com">StackOverflow</a> The new programming question-and-answer forum from <a href="http://www.codinghorror.com/blog/&#39;s">CodingHorror</a> Jeff Atwood and <a href="http://JoelOnSoftware.com">Joel Spolsky</a> has launched. </p>

	<p>Dave Glover wrote a cool post about how simple it is to <a href="http://blogs.msdn.com/dglover/archive/2008/09/11/creating-a-bootable-usb-windows-vista-drive.aspx">create a bootable <span class="caps">USB</span> install disc for Vista</a> and Miguel de Icasa created a <a href="http://tirania.org/blog/archive/2008/Sep-10.html">C# Eval statement</a> and <a href="http://www.mono-project.com/CsharpRepl">console shell</a> for the Mono Project.</p>

	<p>Sir Tim Berners Lee launched the world wide <a href="http://www.webfoundation.org/news/2008/09/welcome-to-the-world-wide-web-foundation.html">Web Foundation</a> to proactively advance the goals that &#8220;a single web&#8221; should be &#8220;open to any device and software&#8221; and to extend the capabilities of the web and ensuring they can be accessed securely by everyone on the planet&#8230; Hard to say <a href="http://arstechnica.com/news.ars/post/20080915-www-creator-berners-lee-launches-ambitious-web-foundation.html">what this all means</a>, at this point.</p>

	<p><a href="http://Present.ly">Present.ly</a> and <a href="http://yammer.com">Yammer</a> launched as attempts at <em>private</em> corporate Twitter implementations.  Present.ly looks most promising, they have the concept of &#8220;groups&#8221; that is missing from twitter, and they have a few different types of posts (questions, urgent messages, group broadcast messages, etc). However, they charge for anything more than the most basic account (ie: no IM without paying). Yammer has a more curious business model (it&#8217;s almost like extortion): employees can join for free based on their email address, companies can then <em>pay</em> to take over their (pre-established on-the-fly) corporate network and exert some control over it, but their Jabber/IM is working great already.</p>

]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/random-news-digest/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SysAdmins, scripters, developers and memes</title>
		<link>http://huddledmasses.org/sysadmins-scripters-developers-and-memes/</link>
		<comments>http://huddledmasses.org/sysadmins-scripters-developers-and-memes/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 03:29:15 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[AboutMe]]></category>
		<category><![CDATA[Memes]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=555</guid>
		<description><![CDATA[So, I&#8217;ve been called out on this latest meme posting by /\/\o\/\/ and although I usually just ignore these things, As with any curious developer, I had to trace this thing back to it&#8217;s root cause &#8230; it turns out this started as a Software Development thing, and it was altered into a sort of [...]]]></description>
			<content:encoded><![CDATA[	<p>So, I&#8217;ve been <a href="http://thepowershellguy.com/blogs/posh/archive/2008/06/17/scripting-sysadmin-meme.aspx">called out</a> on this latest <a href="http://en.wikipedia.org/wiki/Meme">meme</a> posting by <a href="http://thepowershellguy.com/">/\/\o\/\/</a> and although I usually just ignore these things,</p>

	<p>As with any curious developer, I had to <a href="http://get-powershell.com/">trace</a> <a href="http://scriptolog.blogspot.com/2008/06/scripting-sysadmin-meme.html">this</a> <a href="http://www.mindofroot.com/2008/06/10/scriptingsysadmin-meme/">thing</a> <a href="http://larryclarkin.com/2008/06/10/SoftwareDevelopmentMemeOrTagIAmNext.aspx">back</a> <a href="http://www.joshholmes.com/2008/06/06/SoftwareDevelopmentMeme.aspx">to</a> <a href="http://www.jeffblankenburg.com/2008/06/software-development-meme.html">it&#8217;s</a> <a href="http://www.codinggeekette.com/2008/06/sarahs-steps-into-software-development.aspx">root</a> <a href="http://www.michaeleatonconsulting.com/blog/archive/2008/06/04/how-did-you-get-started-in-software-development.aspx">cause</a> &#8230; it turns out this started as a Software Development thing, and it was altered into a sort of SysAdmin thing.</p>

	<p>So, since I&#8217;m putting up with this in the first place, I think I&#8217;ll go back to that original developer-oriented list of questions, if you don&#8217;t mind.  <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/../../../wp-content/plugins/smilingmasses/wink.gif' alt=';-)' class='wp-smiley' /> </p>

	<p><span id="more-555"></span></p>

	<h4>How old were you when you started programming?</h4>

	<p>I got my first computer shortly after my family moved back to the <span class="caps">USA</span> from Costa Rica, just in time for 9th grade &#8230; before that I&#8217;d never seen a computer better than my Atari 6400 game machine.</p>

	<h4>How did you get started in programming?</h4>

	<p>I bought that &#8220;computer&#8221; second-hand &#8212; it was an Atari 800XL, and it came with a cartridge for Atari <span class="caps">BASIC</span>, and a stack of magazines with code in them. That&#8217;s pretty much all there is to it, I was hooked.</p>

	<h4>What was your first language?</h4>

	<p><span class="caps">BASIC</span>. First Atari, then QW, then &#8230; well, Visual Basic Script, believe it or not.</p>

	<h4>What was the first real program you wrote?</h4>

	<p>You mean BlackJack for the Atari doesn&#8217;t count?  I guess the first <em>real</em> program I wrote was one I wrote at work to randomize test cases &#8230;</p>

	<h4>What languages have you used since you started programming? </h4>

	<p>Basic, Visual Basic, C/C++, C#, Java, Perl, <span class="caps">PHP</span>, a bunch of automation languages like batch and shell scripts, VB script and VB for Applications, MS Test Basic, Rational&#8217;s SQABasic, AutoIt, AutoHotkey, ScriptIt, and a slew of web languages like JavaScript, VB Script, <span class="caps">HTML</span>, <span class="caps">XML</span> ... and of course, lets not forget <span class="caps">SQL</span> (although I kind-of wish I could).</p>

	<h4>What was your first professional programming gig?</h4>

	<p>Not counting a few tiny web-sites I did in college &#8230; my first programming job was at Xerox, where I started out doing software testing, started automating the testing, and then moved to writing and maintaining apps, web sites etc.</p>

	<h4>If you knew then what you know now, would you have started programming?</h4>

	<p>Absolutely.  I love what I do, and I love that I work in a job where every year there&#8217;s new languages, new tools, new challenges, and new and more clever solutions.</p>

	<h4>If there is one thing you learned along the way that you would tell new developers, what would it be? </h4>

	<p>There&#8217;s really only three kinds of programmers: Web developers, Database developers, System developers.  Take a database class and a web-design class early on and figure out what you want to be &#8212; then work hard to make sure you don&#8217;t end up being the wrong kind of programmer  <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/../../../wp-content/plugins/smilingmasses/wink.gif' alt=';)' class='wp-smiley' /> </p>

	<h4>What&#8217;s the most fun you&#8217;ve ever had &#8230; programming?</h4>

	<p>I think I&#8217;d have to say that the memory that stands out the most was working on the open source project <a href="http://www.geoshell.org">GeoShell</a> &#8230; it&#8217;s mostly died off now (although I&#8217;m still threatening to ressurect it later this year), but at it&#8217;s height it was a near ideal interaction of passionate users, laid back developers, and <em>cool</em> software that made everyone ask: &#8220;whoah, what&#8217;s that you&#8217;re running?&#8221;</p>

	<p>I guess I should call someone else out, right? That&#8217;s how these silly posts become memes. How about <a href="http://www.leeholmes.com/blog/">Lee Holmes</a>, <a href="http://blog.vyvojar.cz/jachymko/">Jachymko</a> and <a href="http://cmschill.net/stringtheory/">Mark Schill</a> &#8230;</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/sysadmins-scripters-developers-and-memes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Eight Queens in PowerShell</title>
		<link>http://huddledmasses.org/eight-queens-in-powershell/</link>
		<comments>http://huddledmasses.org/eight-queens-in-powershell/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 03:46:31 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[Backtracking]]></category>
		<category><![CDATA[Challenges]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Recursion]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/eight-queens-in-powershell/</guid>
		<description><![CDATA[Well &#8230; my brother called me with an odd compiler problem with his C++ homework today (he&#8217;s working on another degree, and taking some programming courses) ... but the homework problem he was working on was the infamous N Queens problem: Given a chess board of N x N squares, place N queens on the [...]]]></description>
			<content:encoded><![CDATA[	<p>Well &#8230; my brother called me with an odd compiler problem with his C++ homework today (he&#8217;s working on another degree, and taking some programming courses) ... but the homework problem he was working on was the infamous N Queens problem: </p>

	<blockquote>
		<p>Given a chess board of N x N squares, place N queens on the board in such a way than none threatens the others. In chess, a queen can move diagonally or horizontally, so solving this requires placing each queen on her own row and column, and ordered such that none of them are on the same diagonal in either direction.</p>
	</blockquote>

	<p>The problem is solvable using a backtracking recursive algorithm: the program must place a queen on the first row and then find a spot that works for the next row, and continue for each row.  If it can&#8217;t find a spot for a row, it backtracks to the previous row and uses the next legal spot on that row, and if there is none, it backtracks to the previous row, and so on.</p>

	<p>Anyway. There&#8217;s lots of information about this stuff out there on the &#8216;net, including dozens of slides shows and lecture notes from dozens of schools, so I&#8217;m just going to move on to the fun part: my solution in PowerShell. I wrote it just to make sure I understood the algorithm correctly, without giving away the C++ answer as much as a quick web search would. In fact, I followed the restrictions my brother&#8217;s professor had placed on them to break it up into a specific set of functions&#8230;</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">## N-Queens problem using backtracking</span><br />
<span style="color: #666666; font-style: italic;">################################################################################</span><br />
<span style="color: #666666; font-style: italic;">## Backtracking is a problem-solving strategy that, when it reaches an impasse, </span><br />
<span style="color: #666666; font-style: italic;">## retraces its steps in reverse order before trying a new sequence of steps.</span><br />
<br />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$size</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">8</span><span style="color: #333;">&#41;</span> &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># By default, we use a board of size 8</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> Check<span style="color: #66cc66;">-</span>Queen<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$r1</span>,<span style="color: #660033; font-weight: bold;">$c1</span>,<span style="color: #660033; font-weight: bold;">$r2</span>,<span style="color: #660033; font-weight: bold;">$c2</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #000066;">-not</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># they can't be on the same column</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$c1</span> <span style="color: #000066;">-eq</span> <span style="color: #660033; font-weight: bold;">$c2</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-or</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># nor on the same row</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$r1</span> <span style="color: #000066;">-eq</span> <span style="color: #660033; font-weight: bold;">$r2</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-or</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># nor on the same diagonal</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Math<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Abs</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$r1</span><span style="color: #66cc66;">-</span><span style="color: #660033; font-weight: bold;">$r2</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-eq</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Math<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Abs</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$c1</span><span style="color: #66cc66;">-</span><span style="color: #660033; font-weight: bold;">$c2</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span>;<br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">Board</span></span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$board</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$c</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$board</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">switch</span><span style="color: #333;">&#40;</span>0..<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$board</span>.<span style="color: #003366;">Count</span><span style="color: #66cc66;">-</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span><span style="color: #66cc66;">-</span><span style="color: #333399; font-weight: bold; font-style: italic;">eq</span><span style="color: #660033; font-weight: bold;">$c</span><span style="color: #333;">&#125;</span> <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">write-<span style="font-style: normal;">host</span></span> <span style="color: #009900;">&quot;Q&quot;</span> <span style="color: #000066;">-fore</span> red <span style="color: #000066;">-nonew</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; default &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">write-<span style="font-style: normal;">host</span></span> <span style="color: #009900;">&quot;#&quot;</span> <span style="color: #000066;">-nonew</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Queen</span></span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$board</span>,<span style="color: #660033; font-weight: bold;">$row</span>,<span style="color: #660033; font-weight: bold;">$column</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Set the queen location for this row</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$board</span><span style="color: #333;">&#91;</span><span style="color: #660033; font-weight: bold;">$row</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$column</span>;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># if this is the last row, then we're done</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$row</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span> <span style="color: #000066;">-eq</span> <span style="color: #660033; font-weight: bold;">$board</span>.<span style="color: #003366;">Count</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># place the queen in the next row</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># try every column .... </span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$c</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>;<span style="color: #660033; font-weight: bold;">$c</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$board</span>.<span style="color: #003366;">Count</span>; <span style="color: #660033; font-weight: bold;">$c</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clean</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># check it against every prior row</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$r</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>; <span style="color: #660033; font-weight: bold;">$r</span> <span style="color: #000066;">-le</span> <span style="color: #660033; font-weight: bold;">$row</span>; <span style="color: #660033; font-weight: bold;">$r</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$clean</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$clean</span> <span style="color: #000066;">-and</span> <span style="color: #333;">&#40;</span>Check<span style="color: #66cc66;">-</span>Queen <span style="color: #660033; font-weight: bold;">$r</span> <span style="color: #660033; font-weight: bold;">$board</span><span style="color: #333;">&#91;</span><span style="color: #660033; font-weight: bold;">$r</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$row</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</span> <span style="color: #660033; font-weight: bold;">$c</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$clean</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">break</span>; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># if we found the spot, recurse the next row...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$clean</span> <span style="color: #000066;">-and</span><span style="color: #333;">&#40;</span> <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Queen</span></span> <span style="color: #660033; font-weight: bold;">$board</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$row</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</span> <span style="color: #660033; font-weight: bold;">$c</span> <span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #660033; font-weight: bold;">$true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$board</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> <span style="color: #003366; font-weight: bold;">int</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span> <span style="color: #660033; font-weight: bold;">$size</span><br />
<br />
<span style="color: #666666; font-style: italic;"># if starting in 0,0 doesn't work 0,1 will</span><br />
<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Queen</span></span> <span style="color: #660033; font-weight: bold;">$board</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">Board</span></span> <span style="color: #660033; font-weight: bold;">$board</span><br />
<span style="color: #333;">&#125;</span><span style="color: #666699; font-weight: bold;">elseif</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Queen</span></span> <span style="color: #660033; font-weight: bold;">$board</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">Board</span></span> <span style="color: #660033; font-weight: bold;">$board</span><br />
<span style="color: #333;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/eight-queens-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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/images/smilies/../../../wp-content/plugins/smilingmasses/wink.gif' 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>
