<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx</link><description>Summary : Microsoft Windows PowerShell MVP, Don Jones, shows how to use the pipeline to create robust reusable functions. 
 Microsoft Scripting Guy, Ed Wilson, is here. Our guest blogger today is Don Jones. 
 
 
 Don Jones is a Windows PowerShell</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx#3555294</link><pubDate>Wed, 27 Feb 2013 15:40:27 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3555294</guid><dc:creator>happysysadm</dc:creator><description>&lt;p&gt;@Karl,&lt;/p&gt;
&lt;p&gt;yes, what this function returns is an object, so where-object works as you expect.&lt;/p&gt;
&lt;p&gt;Where-object receives as input a psobject: get-help where-object&lt;/p&gt;
&lt;p&gt;Don, there is a mistake on line 43. You should replace &lt;/p&gt;
&lt;p&gt;Add-Member –membertype NoteProperty –name OSBuild –version ($os.buildnumber) –passthru |&lt;/p&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;p&gt;Add-Member –membertype NoteProperty –name OSBuild –value ($os.buildnumber) –passthru |&lt;/p&gt;
&lt;p&gt;Carlo&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3555294" width="1" height="1"&gt;</description></item><item><title>re: Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx#3552328</link><pubDate>Wed, 13 Feb 2013 19:16:33 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3552328</guid><dc:creator>Karl</dc:creator><description>&lt;p&gt;Is it possible to pipe data to the funciton and specify the log file like this?:&lt;/p&gt;
&lt;p&gt;Get-ADComputer –filter * | Select-Object @{label=&amp;#39;computername&amp;#39;,expression={$_.Name}} | Get-Info &amp;quot;C:\todayscomputersthatneedpatching.txt&amp;quot; | Where-Object –filterscript { $_.OSBuild –eq 7600 –and $_.SPVersion –ne 2 } | Export-CSV c:\needs-patched.txt&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3552328" width="1" height="1"&gt;</description></item><item><title>re: Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx#3428216</link><pubDate>Wed, 11 May 2011 15:06:53 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3428216</guid><dc:creator>sgrinker</dc:creator><description>&lt;p&gt;It might be helpful if I clarify the article I had in mind. &amp;nbsp;I&amp;#39;m not talking about explaining the basics of the pipeline in a simple command like.&lt;/p&gt;
&lt;p&gt;Get-Service | Where-Object {$_.Status -eq &amp;quot;Running&amp;quot;}&lt;/p&gt;
&lt;p&gt;Although such an article may be helpful, I was thinking more of a deeper dive into the mechanics of the pipeline when using advanced functions like in Don&amp;#39;s article. &amp;nbsp; &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3428216" width="1" height="1"&gt;</description></item><item><title>re: Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx#3428209</link><pubDate>Wed, 11 May 2011 14:36:38 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3428209</guid><dc:creator>sgrinker</dc:creator><description>&lt;p&gt;Great article! &amp;nbsp;Regarding the Write-Output versus direct New-Object &amp;#39;spewing&amp;#39; out the data, I see the merits of both approaches. &amp;nbsp;Depends on personal preference and the audience on who would be trying to understand the script. &amp;nbsp;Along those lines though, it might be worth another article attempting to demistify the &amp;quot;magic&amp;quot; of the pipeline. &amp;nbsp;Something that would help to walk through the what, when, why, and how things are (or are not) passed to the pipeline, and when they get consumed. &amp;nbsp;I know there is no real hard/fast rule for all cases, so not sure what the article would look like. &amp;nbsp;Any thoughts?&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3428209" width="1" height="1"&gt;</description></item><item><title>re: Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx#3428205</link><pubDate>Wed, 11 May 2011 14:24:17 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3428205</guid><dc:creator>coderaven</dc:creator><description>&lt;p&gt;Bump that last comment by CrazyDave. That would be a good post if not already there to make sure output comes as objects instead of text.&lt;/p&gt;
&lt;p&gt;Very good article!!! I have some thing simular but this is a much better method. Thanks!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3428205" width="1" height="1"&gt;</description></item><item><title>re: Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx#3427929</link><pubDate>Tue, 10 May 2011 19:39:30 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3427929</guid><dc:creator>CrazyDave</dc:creator><description>&lt;p&gt;I, personally would simplify the Object Creation to a much cleaner:&lt;/p&gt;
&lt;p&gt;New-Object PSObject -Property @{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; ComputerName = $computer&lt;/p&gt;
&lt;p&gt; &amp;nbsp; OSVersion = $os.caption&lt;/p&gt;
&lt;p&gt; &amp;nbsp; OSBuild = $os.buildnumber&lt;/p&gt;
&lt;p&gt; &amp;nbsp; BIOSSerial =$bios.serialnumber&lt;/p&gt;
&lt;p&gt; &amp;nbsp; SPVersion = $os.servicepackmajorversion&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;There&amp;#39;s no need to call &amp;quot;Write-Output $obj&amp;quot; in this example, you can just create the New-Object and it will automatically be &amp;#39;spewed&amp;#39; to the output...&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3427929" width="1" height="1"&gt;</description></item><item><title>re: Use the Pipeline to Create Robust PowerShell Functions</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/10/use-the-pipeline-to-create-robust-powershell-functions.aspx#3427744</link><pubDate>Tue, 10 May 2011 09:12:03 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3427744</guid><dc:creator>Klaus Schulte</dc:creator><description>&lt;p&gt;RT or Pingback :-) Thank you, Don, for this awesome article. &lt;/p&gt;
&lt;p&gt;Hello Don,&lt;/p&gt;
&lt;p&gt;this is seriously that kind of stuff I&amp;#39;ve got to dive deeper in!&lt;/p&gt;
&lt;p&gt;Up to now I mostly ignored advanced functions and the fact that I have to return objects from functions! So I definitely will be following your advice and have a closer look at adv. functions! Besides it still seems to be a kind of magic how Powershell handles the input from the pipeline that has kept me apart from believing that it really is that simple to use it.&lt;/p&gt;
&lt;p&gt;So I suppose finding information about parameter attributes, parameter validation, the structure of advanced functions and objects should be the next step into advanced functions.&lt;/p&gt;
&lt;p&gt;kind regrads, Klaus (K_Schulte)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3427744" width="1" height="1"&gt;</description></item></channel></rss>