{"id":589,"date":"2018-06-03T08:00:51","date_gmt":"2018-06-03T14:00:51","guid":{"rendered":"https:\/\/practicalpowershell.com\/?p=589"},"modified":"2020-03-14T16:45:03","modified_gmt":"2020-03-14T22:45:03","slug":"to-filter-or-be-where","status":"publish","type":"post","link":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/","title":{"rendered":"To Filter or Be Where?"},"content":{"rendered":"<p><a href=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png?resize=75%2C92&#038;ssl=1\" alt=\"\" width=\"75\" height=\"92\" class=\"alignleft size-full wp-image-590\" \/><\/a>When working with data sets and PowerShell, knowing how to handle them can be a tricky proposition. It also depends on the size of the data that is being analyzed or manipulated with PowerShell. What works for one, ten or even a hundred objects, may not scale efficiently past 1,000, 10,000 or even more. In this Tip of the Week we discuss two common methods for working with data sets and PowerShell.<BR><br \/>\n<em>Where<\/em><BR><br \/>\nThis commonly used operator allows us to decide what to tell PowerShell to look for in a set of results. For example, if we are working in Exchange Online and moving mailboxes to or from an on-premises server, we may want to look at only complete migrations or maybe any migration that has failed to see what is wrong with this. This can be performed with the Where operator, like so:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nGet-MigrationUsers | Where {$_.Status -eq &#039;Failed&#039;}<br \/>\n[\/sourcecode]<br \/>\nThis one-liner works well for finding these results.<BR><br \/>\n<em>Filter<\/em><BR><br \/>\nHowever, the same operator when working with large data sets, could cause performance issues. For example, if we were to work within PowerShell and perform AD queries for managers or users, the Where operator is actually very slow and could add seconds or maybe even an additional minute to process a single user object. Filter is our other option for narrowing down the results:<br \/>\n[sourcecode language=&#8221;powershell&#8221;]<br \/>\nGet-ADUser -Filter {SamAccountName -eq $ManagerID}<br \/>\n[\/sourcecode]<br \/>\nWith the use of the Filter operator, this one-liner now only takes about a second per object versus over a minute in some environments. Depending on a script, this could shorten a long running script to a much more manageable time frame.<BR><br \/>\n<em>Caveat<\/em><BR><br \/>\nFilter is not available with every cmdlet, so your mileage will vary!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When working with data sets and PowerShell, knowing how to handle them can be a tricky proposition. It also depends on the size of the data that is being analyzed or manipulated with PowerShell. What works for one, ten or even a hundred objects, may not scale efficiently past 1,000, 10,000 or even more. In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rop_custom_images_group":[],"rop_custom_messages_group":[],"rop_publish_now":"initial","rop_publish_now_accounts":[],"rop_publish_now_history":[],"rop_publish_now_status":"pending","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-589","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>To Filter or Be Where? - Practical PowerShell<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"To Filter or Be Where? - Practical PowerShell\" \/>\n<meta property=\"og:description\" content=\"When working with data sets and PowerShell, knowing how to handle them can be a tricky proposition. It also depends on the size of the data that is being analyzed or manipulated with PowerShell. What works for one, ten or even a hundred objects, may not scale efficiently past 1,000, 10,000 or even more. In [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/\" \/>\n<meta property=\"og:site_name\" content=\"Practical PowerShell\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-03T14:00:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-14T22:45:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png\" \/>\n<meta name=\"author\" content=\"damian\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"damian\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/\"},\"author\":{\"name\":\"damian\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"headline\":\"To Filter or Be Where?\",\"datePublished\":\"2018-06-03T14:00:51+00:00\",\"dateModified\":\"2020-03-14T22:45:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/\"},\"wordCount\":293,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/PowerShellIcon.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/\",\"name\":\"To Filter or Be Where? - Practical PowerShell\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/PowerShellIcon.png\",\"datePublished\":\"2018-06-03T14:00:51+00:00\",\"dateModified\":\"2020-03-14T22:45:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/PowerShellIcon.png?fit=75%2C92&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/practicalpowershell.com\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/PowerShellIcon.png?fit=75%2C92&ssl=1\",\"width\":75,\"height\":92},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/to-filter-or-be-where\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/practicalpowershell.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"To Filter or Be Where?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#website\",\"url\":\"https:\\\/\\\/practicalpowershell.com\\\/\",\"name\":\"Practical PowerShell\",\"description\":\"PowerShell books written by experts\",\"publisher\":{\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/practicalpowershell.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/practicalpowershell.com\\\/#\\\/schema\\\/person\\\/4d0733c81966e744aabbb49f56d64deb\",\"name\":\"damian\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\",\"caption\":\"damian\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"To Filter or Be Where? - Practical PowerShell","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/","og_locale":"en_US","og_type":"article","og_title":"To Filter or Be Where? - Practical PowerShell","og_description":"When working with data sets and PowerShell, knowing how to handle them can be a tricky proposition. It also depends on the size of the data that is being analyzed or manipulated with PowerShell. What works for one, ten or even a hundred objects, may not scale efficiently past 1,000, 10,000 or even more. In [&hellip;]","og_url":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/","og_site_name":"Practical PowerShell","article_published_time":"2018-06-03T14:00:51+00:00","article_modified_time":"2020-03-14T22:45:03+00:00","og_image":[{"url":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png","type":"","width":"","height":""}],"author":"damian","twitter_card":"summary_large_image","twitter_misc":{"Written by":"damian","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#article","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/"},"author":{"name":"damian","@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"headline":"To Filter or Be Where?","datePublished":"2018-06-03T14:00:51+00:00","dateModified":"2020-03-14T22:45:03+00:00","mainEntityOfPage":{"@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/"},"wordCount":293,"commentCount":0,"publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"image":{"@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/","url":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/","name":"To Filter or Be Where? - Practical PowerShell","isPartOf":{"@id":"https:\/\/practicalpowershell.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#primaryimage"},"image":{"@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#primaryimage"},"thumbnailUrl":"https:\/\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png","datePublished":"2018-06-03T14:00:51+00:00","dateModified":"2020-03-14T22:45:03+00:00","breadcrumb":{"@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/practicalpowershell.com\/to-filter-or-be-where\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#primaryimage","url":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png?fit=75%2C92&ssl=1","contentUrl":"https:\/\/i0.wp.com\/practicalpowershell.com\/wp-content\/uploads\/2020\/03\/PowerShellIcon.png?fit=75%2C92&ssl=1","width":75,"height":92},{"@type":"BreadcrumbList","@id":"https:\/\/practicalpowershell.com\/to-filter-or-be-where\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/practicalpowershell.com\/"},{"@type":"ListItem","position":2,"name":"To Filter or Be Where?"}]},{"@type":"WebSite","@id":"https:\/\/practicalpowershell.com\/#website","url":"https:\/\/practicalpowershell.com\/","name":"Practical PowerShell","description":"PowerShell books written by experts","publisher":{"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/practicalpowershell.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/practicalpowershell.com\/#\/schema\/person\/4d0733c81966e744aabbb49f56d64deb","name":"damian","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g","caption":"damian"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/d5a8cc64a5aa27558a897b108e3be1a89859511a3fd26176dac292f26e7a4ae4?s=96&d=mm&r=g"}}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/589","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/comments?post=589"}],"version-history":[{"count":2,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/589\/revisions"}],"predecessor-version":[{"id":592,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/posts\/589\/revisions\/592"}],"wp:attachment":[{"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/media?parent=589"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/categories?post=589"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/practicalpowershell.com\/wp-json\/wp\/v2\/tags?post=589"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}