<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>When NOT To Use &amp;quot;WHERE&amp;quot;</title><link>http://blogs.msdn.com/b/powershell/archive/2008/08/12/when-not-to-use-where.aspx</link><description>I've seen a number of scripts that look like this: 
 
 GET-XXXX | Where {$_.name -eq "foo"} 
 or 
 
 GET-XXXX | Where {$_.name -like "A*"} 
 Whenever you see code like this, it is a sign that the GET-XXXX is not designed correctly. (NOTE: GET-XXXX</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: When NOT To Use "WHERE"</title><link>http://blogs.msdn.com/b/powershell/archive/2008/08/12/when-not-to-use-where.aspx#8885268</link><pubDate>Thu, 21 Aug 2008 19:02:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8885268</guid><dc:creator>Bryan Fairchild</dc:creator><description>&lt;p&gt;Yes there are many ways to filter and select locally without using WHERE, but when dealing with remote systems and WMI WHERE is a necessity. Hopefully with a future release of powershell some of the cmdlets will have built in remoting capability.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8885268" width="1" height="1"&gt;</description></item><item><title>re: When NOT To Use "WHERE"</title><link>http://blogs.msdn.com/b/powershell/archive/2008/08/12/when-not-to-use-where.aspx#8869894</link><pubDate>Fri, 15 Aug 2008 18:21:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8869894</guid><dc:creator>Andrew</dc:creator><description>&lt;p&gt;File System APIs have native filtering - How does one filter based on date without using where?&lt;/p&gt;
&lt;p&gt;e.g.&lt;/p&gt;
&lt;p&gt;get-childitem | where-object {$_.lastwritetime -ge [datetime]::Today}&lt;/p&gt;
&lt;p&gt;Or, is is just by name that you can do this with the fs and get-childitem?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8869894" width="1" height="1"&gt;</description></item><item><title>re: When NOT To Use "WHERE"</title><link>http://blogs.msdn.com/b/powershell/archive/2008/08/12/when-not-to-use-where.aspx#8867028</link><pubDate>Thu, 14 Aug 2008 18:05:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8867028</guid><dc:creator>Don Jones</dc:creator><description>&lt;p&gt;Sometimes it's not the cmdlet, it's that the user just isn't aware :). I tell my students to &amp;quot;move filtering as far to the left of the command-line as possible,&amp;quot; so they have a general rule to read up on the cmdlets they're using and see if they do support -filter or something.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8867028" width="1" height="1"&gt;</description></item><item><title>re: When NOT To Use "WHERE"</title><link>http://blogs.msdn.com/b/powershell/archive/2008/08/12/when-not-to-use-where.aspx#8855593</link><pubDate>Wed, 13 Aug 2008 06:16:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8855593</guid><dc:creator>Aleksei Guzev</dc:creator><description>&lt;p&gt;Since most comdlets deal with sequences of items, filter seems being a common attribute. That is why it could be worth providing a special syntax rule for filtering. One could treat filtered query as a &amp;quot;protected statement&amp;quot; in some programming languages. The statement must be true if some condition was satisfied.&lt;/p&gt;
&lt;p&gt;Providing special syntax could solve the problem of interaction between &amp;quot;where-object&amp;quot; and the preceeding get-* cmdlet. Cmdlet author could specify whether the code supports filtering on its own by implementing corresponding interface. If so PowerShell should pass the query text to the cmdlet via property or method. Else PowerShell calls &amp;quot;where-object&amp;quot;. &lt;/p&gt;
&lt;p&gt;This way we could eliminate feature and code duplication in the user's eyes. And more important is to eliminate the ambiguity.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8855593" width="1" height="1"&gt;</description></item><item><title>re: When NOT To Use "WHERE"</title><link>http://blogs.msdn.com/b/powershell/archive/2008/08/12/when-not-to-use-where.aspx#8853500</link><pubDate>Tue, 12 Aug 2008 23:44:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8853500</guid><dc:creator>George Tsiokos</dc:creator><description>&lt;p&gt;Have you considered translating the input&lt;/p&gt;
&lt;p&gt;GET-XXXX | Where {$_.name -eq &amp;quot;foo&amp;quot;}&lt;/p&gt;
&lt;p&gt;to GET-XXXX -Name &amp;quot;foo&amp;quot;&lt;/p&gt;
&lt;p&gt;The | WHERE {...} syntax is the easiest to write and understand. This seems to be a simple mapping in which the where-object scriptblock is translated back to -name (in this case).&lt;/p&gt;
&lt;p&gt;GET-XXXX | Where {$_.path -eq &amp;quot;foo&amp;quot;}&lt;/p&gt;
&lt;p&gt;to GET-XXXX -include YYYY&lt;/p&gt;
&lt;p&gt;The include translation probably needs some extra attribute(s) on the cmdlet to map the where-object scriptblock to include/exclude/etc string(s)...&lt;/p&gt;
&lt;p&gt;The ultimate extension would map where-object scriptblock to a cmdlet's filter by using expression trees (where the cmdlet translates the expression tree to the provider specific filter expression) :)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8853500" width="1" height="1"&gt;</description></item></channel></rss>