{"id":5611,"date":"2008-08-12T07:32:00","date_gmt":"2008-08-12T07:32:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2008\/08\/12\/when-not-to-use-quotwherequot\/"},"modified":"2019-02-18T13:13:04","modified_gmt":"2019-02-18T20:13:04","slug":"when-not-to-use-quotwherequot","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/when-not-to-use-quotwherequot\/","title":{"rendered":"When NOT To Use &#038;quot;WHERE&#038;quot;"},"content":{"rendered":"<p>I&#8217;ve seen a number of scripts that look like this:<\/p>\n<blockquote>\n<p>&nbsp;GET-XXXX | Where {$_.name -eq &#8220;foo&#8221;}&nbsp;<\/p>\n<\/blockquote>\n<p>or<\/p>\n<blockquote>\n<p>GET-XXXX | Where {$_.name -like &#8220;A*&#8221;}<\/p>\n<\/blockquote>\n<p>Whenever you see code like this, it is a sign that the GET-XXXX is not designed correctly.&nbsp;&nbsp; (NOTE:&nbsp; GET-XXXX is NOT a porn retrieval cmdlet&nbsp;&#8211; it is a standin for any GET-&lt;SOMETHING&gt; cmdlet).<\/p>\n<p>The whole point of a cmdlet is to think about the USER and deliver the correct experience.&nbsp; As a GENERAL rule, we encourage cmdlet developers to leverage PowerShell utilities like WHERE, SORT, FORMAT, etc and NOT to put that function into their cmdlets.&nbsp; The reason for this is that this makes the cmdlet more complicated and provides NEW semantics that the user has to learn.<\/p>\n<p>There are a couple of exceptions to this general rule:<\/p>\n<ol>\n<li>GET cmdlets should support -NAME.&nbsp; A VERY large percentage of the time people do a GET, they want a specific item or a set of NAMED items so you should hotrod this experience by directly supporting it.<\/li>\n<ul>\n<li>NAME should take a multiple inputs and support wildcards. e.g.&nbsp; &#8220;get-process -name *ss,a*&#8221;<\/li>\n<\/ul>\n<li>GET cmdlets should support -FILTER if your getter has native query capabilities.&nbsp; Users can decide whether the perf advantage of your cmdlet is worth learning the new syntax [in most cases it will be].<\/li>\n<ul>\n<li>e.g.&nbsp; If\/when there are a set of AD cmdlets, they should support -FILTER and take an LDAP query.&nbsp; <\/li>\n<li>The APIs that support Get-Process have no native filtering which is why it doesn&#8217;t support it but the file system APIs do which is why &#8220;DIR -FILTER A*&#8221; works.<\/li>\n<\/ul>\n<\/ol>\n<p>Cheers!<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows Management Partner Architect<br \/>Visit the Windows PowerShell Team blog at:&nbsp;&nbsp;&nbsp; <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at:&nbsp; <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve seen a number of scripts that look like this: &nbsp;GET-XXXX | Where {$_.name -eq &#8220;foo&#8221;}&nbsp; or GET-XXXX | Where {$_.name -like &#8220;A*&#8221;} Whenever you see code like this, it is a sign that the GET-XXXX is not designed correctly.&nbsp;&nbsp; (NOTE:&nbsp; GET-XXXX is NOT a porn retrieval cmdlet&nbsp;&#8211; it is a standin for any GET-&lt;SOMETHING&gt; [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[4],"class_list":["post-5611","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-howto"],"acf":[],"blog_post_summary":"<p>I&#8217;ve seen a number of scripts that look like this: &nbsp;GET-XXXX | Where {$_.name -eq &#8220;foo&#8221;}&nbsp; or GET-XXXX | Where {$_.name -like &#8220;A*&#8221;} Whenever you see code like this, it is a sign that the GET-XXXX is not designed correctly.&nbsp;&nbsp; (NOTE:&nbsp; GET-XXXX is NOT a porn retrieval cmdlet&nbsp;&#8211; it is a standin for any GET-&lt;SOMETHING&gt; [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/5611","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=5611"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/5611\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=5611"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=5611"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=5611"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}