{"id":8400,"date":"2021-05-14T12:44:35","date_gmt":"2021-05-14T16:44:35","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=8400"},"modified":"2021-05-14T17:26:41","modified_gmt":"2021-05-14T21:26:41","slug":"friday-fun-custom-grouping-with-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","title":{"rendered":"Friday Fun &#8211; Custom Grouping with PowerShell"},"content":{"rendered":"\n<div class=\"wp-block-image is-style-default\"><figure class=\"alignleft size-large\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"213\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg\" alt=\"Photo by Clem Onojeghuo from Pexels\" class=\"wp-image-8401\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg 320w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897-300x200.jpg 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>The other day I was answering a question in the PowerShell Facebook group. This person was getting data from Active Directory and trying to organize the results in a way that met his business requirements. My suggestion was to use Group-Object and a custom grouping property. I am assuming you are familiar with Group-Object. You can specify a property name, and the incoming objects are grouped based on the property value. This is a handy way of organizing things into buckets. Sometimes you just want to group results, and other times you want to do something with each group. But if you read the full help and examples for Group-Object (you did, right?), you would see that there is a way to create a custom grouping. I thought I'd give you a few examples of how this works.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Custom Property Script Block<\/h2>\n\n\n\n<p>This conventional way to use Group-Object is to pipe one command to it and organize the incoming objects based on a property name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-Childitem&nbsp;c:\\scripts&nbsp;-file&nbsp;|&nbsp;Group-Object&nbsp;-Property&nbsp;Extension<\/code><\/pre>\n\n\n\n<p>You can try this example with any path on your computer to see how this works. However, PowerShell is magical, or at least flexible, and you can group on something you create out of thin air. You can use a script block and $_ to represent each object. This is the same concept in Select-Object to create custom properties. Although in this case, the Group-Object script block doesn't need to be named. Here's a simple example.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-ChildItem&nbsp;c:\\scripts&nbsp;-file&nbsp;-Recurse&nbsp;-exclude&nbsp;*.exe&nbsp;|&nbsp;\nGroup-Object&nbsp;-property&nbsp;{$_.LastWriteTime.Year}<\/code><\/pre>\n\n\n\n<p>The files will be grouped based on the Year property of the LastWriteTime property.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/group-year.png\"><img loading=\"lazy\" decoding=\"async\" width=\"867\" height=\"354\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/group-year.png\" alt=\"\" class=\"wp-image-8402\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/group-year.png 867w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/group-year-300x122.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/group-year-768x314.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/group-year-850x347.png 850w\" sizes=\"auto, (max-width: 867px) 100vw, 867px\" \/><\/a><\/figure>\n\n\n\n<p>As you can see, I've been doing this scripting thing for awhile. This example is simple and is easy to write in the console. But there's no limit to what you can put in the script block. Here's a more complex grouping and one that is analogous to what my friend was trying to do with Active Directory.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Get-ChildItem&nbsp;c:\\scripts&nbsp;-file&nbsp;|&nbsp;Group-Object&nbsp;-Property&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;-Regex&nbsp;($_.extension)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"\\.(ps(d|m)?1(xml)?)$\"&nbsp;{\"PowerShell\"}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"\\.(bat|cmd|sh)$\"&nbsp;{\"Shell\"}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"\\.(txt|md)$\"&nbsp;{\"Text\"}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"\\.(xml|json|csv|yml)$\"&nbsp;{\"Data\"}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"\\.(zip|rar)$\"&nbsp;{&nbsp;\"Archive\"}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Default&nbsp;{\"Other\"}\n&nbsp;&nbsp;&nbsp;&nbsp;}\n}<\/code><\/pre>\n\n\n\n<p>The grouping is using a Switch statement. If you aren't familiar with it, start with reading the about_Switch help topic. I am looking at the extension property and doing a regular expression comparison. Switch statements don't have to be this complex, but this one is. If the file matches a pattern, the output value will be the corresponding string.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"404\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png\" alt=\"\" class=\"wp-image-8404\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping.png 766w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/custom-grouping-300x158.png 300w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/a><\/figure>\n\n\n\n<p>As an alternative, you could use an If\/ElseIF statement. Remember that in a Switch statement, PowerShell tests for all possible matches. If you don't want that behavior, and there is a chance you might get multiple matches, you can use Break.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">\"\\.(ps(d|m)?1(xml)?)$\"&nbsp;{\"PowerShell\";Break}<\/code><\/pre>\n\n\n\n<p>In my case, I wrote the regex patterns to avoid duplicate matching. And even though the Default entry isn't required, when grouping like this I would include it. Otherwise, the grouping result name will be blank. And in some cases, like when grouping certain Active Directory objects, will throw an exception.<\/p>\n\n\n\n<p>Here's a final example using Active Directory. I want to organize users by department into larger \"buckets\".<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$Operations&nbsp;=&nbsp;\"IT\",&nbsp;\"Dev\",&nbsp;\"Accounting\",&nbsp;\"Executive\",&nbsp;\"Manufacturing\",&nbsp;\"Payroll\",&nbsp;\"Quality&nbsp;Assurance\"\n$Sales&nbsp;=&nbsp;\"Sales\",&nbsp;\"Marketing\"\n$Internal&nbsp;=&nbsp;\"Physical&nbsp;Plant\",&nbsp;\"Development\"\n$Customer&nbsp;=&nbsp;\"Customer&nbsp;Service\",&nbsp;\"Consumer&nbsp;Affairs\",&nbsp;\"Public&nbsp;Affairs\"\n\nGet-ADUser&nbsp;-Filter&nbsp;*&nbsp;-Properties&nbsp;title,&nbsp;department,&nbsp;Displayname&nbsp;|\nGroup-Object&nbsp;-property&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;$vars&nbsp;=&nbsp;&nbsp;Get-Variable&nbsp;-Name&nbsp;\"Operations\",&nbsp;\"Sales\",&nbsp;\"Internal\",&nbsp;\"Customer\"\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($_.department)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;($v&nbsp;in&nbsp;$vars)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($v.value&nbsp;-contains&nbsp;$_.department)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$class&nbsp;=&nbsp;$v.name\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Break\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;#foreach&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(-not&nbsp;$class)&nbsp;{\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$class&nbsp;=&nbsp;&nbsp;\"Uncategorized\"\n&nbsp;&nbsp;&nbsp;&nbsp;}\n&nbsp;&nbsp;&nbsp;&nbsp;$class\n}&nbsp;<\/code><\/pre>\n\n\n\n<p>I define variables that contain the department names. The grouping uses a custom property that loops through the variables and tests if the department name belongs to the variable. If so, I'm using the variable name as the output. Not that I'm taking into consideration accounts with no department and those that might not be in my list. Without this, I get an \"Object reference not to to an instance of an object\" error.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/dept-group.png\"><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"168\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/dept-group.png\" alt=\"\" class=\"wp-image-8406\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/dept-group.png 504w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/dept-group-300x100.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>I'm always telling people to focus on \"objects in the pipeline\" when working with PowerShell. This is a great example. Obviously start with the objects you have, but don't let that stop you from using objects in creative ways. I'm always looking for opportunities to do more and custom grouping properties is a handy tool for your PowerShell toolbox.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The other day I was answering a question in the PowerShell Facebook group. This person was getting data from Active Directory and trying to organize the results in a way that met his business requirements. My suggestion was to use Group-Object and a custom grouping property. I am assuming you are familiar with Group-Object. You&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New on the blog: Friday Fun - Custom Grouping with #PowerShell","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7,271,4,8],"tags":[342,534,82,540],"class_list":["post-8400","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-friday-fun","category-powershell","category-scripting","tag-group-object","tag-powershell","tag-scriptblock","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun - Custom Grouping with PowerShell &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"PowerShell is all about objects in the pipeline. Here are a few examples of creating custom groupings using a PowerShell script block.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun - Custom Grouping with PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"PowerShell is all about objects in the pipeline. Here are a few examples of creating custom groupings using a PowerShell script block.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-14T16:44:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-14T21:26:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun &#8211; Custom Grouping with PowerShell\",\"datePublished\":\"2021-05-14T16:44:35+00:00\",\"dateModified\":\"2021-05-14T21:26:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/\"},\"wordCount\":639,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/pexels-clem-onojeghuo-375897.jpg\",\"keywords\":[\"Group-Object\",\"PowerShell\",\"ScriptBlock\",\"Scripting\"],\"articleSection\":[\"Active Directory\",\"Friday Fun\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/\",\"name\":\"Friday Fun - Custom Grouping with PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/pexels-clem-onojeghuo-375897.jpg\",\"datePublished\":\"2021-05-14T16:44:35+00:00\",\"dateModified\":\"2021-05-14T21:26:41+00:00\",\"description\":\"PowerShell is all about objects in the pipeline. Here are a few examples of creating custom groupings using a PowerShell script block.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/pexels-clem-onojeghuo-375897.jpg\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/pexels-clem-onojeghuo-375897.jpg\",\"width\":320,\"height\":213},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/8400\\\/friday-fun-custom-grouping-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun &#8211; Custom Grouping with PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Friday Fun - Custom Grouping with PowerShell &#8226; The Lonely Administrator","description":"PowerShell is all about objects in the pipeline. Here are a few examples of creating custom groupings using a PowerShell script block.","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:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun - Custom Grouping with PowerShell &#8226; The Lonely Administrator","og_description":"PowerShell is all about objects in the pipeline. Here are a few examples of creating custom groupings using a PowerShell script block.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2021-05-14T16:44:35+00:00","article_modified_time":"2021-05-14T21:26:41+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun &#8211; Custom Grouping with PowerShell","datePublished":"2021-05-14T16:44:35+00:00","dateModified":"2021-05-14T21:26:41+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/"},"wordCount":639,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg","keywords":["Group-Object","PowerShell","ScriptBlock","Scripting"],"articleSection":["Active Directory","Friday Fun","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/","name":"Friday Fun - Custom Grouping with PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg","datePublished":"2021-05-14T16:44:35+00:00","dateModified":"2021-05-14T21:26:41+00:00","description":"PowerShell is all about objects in the pipeline. Here are a few examples of creating custom groupings using a PowerShell script block.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/05\/pexels-clem-onojeghuo-375897.jpg","width":320,"height":213},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8400\/friday-fun-custom-grouping-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Friday Fun &#8211; Custom Grouping with PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":2330,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2330\/friday-fun-get-latest-powershell-scripts\/","url_meta":{"origin":8400,"position":0},"title":"Friday Fun: Get Latest PowerShell Scripts","author":"Jeffery Hicks","date":"May 18, 2012","format":false,"excerpt":"Probably like many of you I keep almost all of my scripts in a single location. I'm also usually working on multiple items at the same time. Some times I have difficult remembering the name of a script I might have been working on a few days ago that I\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/get-latestscript-300x133.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":112,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/112\/powershell-mini-conference\/","url_meta":{"origin":8400,"position":1},"title":"PowerShell Mini-Conference","author":"Jeffery Hicks","date":"June 11, 2007","format":false,"excerpt":"If you've got some free time in early November and want to get up to speed on PowerShell in the least amount of time, then come to Las Vegas. Don Jones (PoweShell MVP) and I will be running a 2 day PowerShell mini-conference. This will be an intense 2 days\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":898,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/898\/powershell-the-ultimate-ginsu-knife\/","url_meta":{"origin":8400,"position":2},"title":"PowerShell: The Ultimate Ginsu Knife","author":"Jeffery Hicks","date":"September 1, 2010","format":false,"excerpt":"You don't have to stay up until the wee hours of the morning looking for an amazing tool that slices and dices like the famed Ginsu Knife. Are you looking for a way to speed up your work? Are you tired of the same old routine? Would you be surprised\u2026","rel":"","context":"In &quot;Active Directory&quot;","block_context":{"text":"Active Directory","link":"https:\/\/jdhitsolutions.com\/blog\/category\/active-directory\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3715,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3715\/friday-fun-the-measure-of-a-folder\/","url_meta":{"origin":8400,"position":3},"title":"Friday Fun: The Measure of a Folder","author":"Jeffery Hicks","date":"February 21, 2014","format":false,"excerpt":"Last week, I demonstrated how to measure a file with PowerShell. This week let's go a step further and measure a folder. I'm going to continue to use Measure-Object although this time I will need to use it to measure numeric property values. Here's the complete function after which I'll\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"ruler","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/02\/ruler-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":8593,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8593\/theres-a-file-in-my-powershell-bucket\/","url_meta":{"origin":8400,"position":4},"title":"There&#8217;s a File in My PowerShell Bucket","author":"Jeffery Hicks","date":"September 28, 2021","format":false,"excerpt":"If there's one task I've never stopped doing, it is finding files. I am constantly creating new ways to organize files and display them in a meaningful format. Naturally, PowerShell is a great tool for this task. Get-ChildItem is obviously the proper starting point. The cmdlet works fine in getting\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/09\/fileage3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/09\/fileage3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/09\/fileage3.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/09\/fileage3.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":4305,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4305\/what-powershell-script-was-i-working-on\/","url_meta":{"origin":8400,"position":5},"title":"What PowerShell Script Was I Working On?","author":"Jeffery Hicks","date":"March 24, 2015","format":false,"excerpt":"Last week I shared a script for finding recently modified files in a given directory. In fact, it wouldn't be that difficult to find the last files I was working on and open them in the PowerShell ISE. Assuming my Get-RecentFile function is loaded it is a simple as this:\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8400","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=8400"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/8400\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=8400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=8400"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=8400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}