{"id":8811,"date":"2007-01-10T23:30:00","date_gmt":"2007-01-10T23:30:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/01\/10\/sorting-out-groupby\/"},"modified":"2019-02-18T13:20:53","modified_gmt":"2019-02-18T20:20:53","slug":"sorting-out-groupby","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/sorting-out-groupby\/","title":{"rendered":"Sorting out -GroupBy"},"content":{"rendered":"<p><!--\n \/* Font Definitions *\/\n @font-face\n\t{font-family:\"Cambria Math\";\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n@font-face\n\t{font-family:Cambria;\n\tpanose-1:2 4 5 3 5 4 6 3 2 4;}\n@font-face\n\t{font-family:Calibri;\n\tpanose-1:2 15 5 2 2 2 4 3 2 4;}\n@font-face\n\t{font-family:\"Lucida Console\";\n\tpanose-1:2 11 6 9 4 5 4 2 2 4;}\n \/* Style Definitions *\/\n p.MsoNormal, li.MsoNormal, div.MsoNormal\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.75in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\nh2\n\t{mso-style-link:\"Heading 2 Char\";\n\tmargin-top:10.0pt;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.75in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tpage-break-after:avoid;\n\tfont-size:13.0pt;\n\tfont-family:\"Cambria\",\"serif\";\n\tcolor:#4F81BD;\n\tfont-weight:bold;}\na:link, span.MsoHyperlink\n\t{color:blue;\n\ttext-decoration:underline;}\na:visited, span.MsoHyperlinkFollowed\n\t{color:purple;\n\ttext-decoration:underline;}\np\n\t{margin-right:0in;\n\tmargin-left:0in;\n\tfont-size:12.0pt;\n\tfont-family:\"Times New Roman\",\"serif\";}\np.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph\n\t{margin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\nspan.Heading2Char\n\t{mso-style-name:\"Heading 2 Char\";\n\tmso-style-link:\"Heading 2\";\n\tfont-family:\"Cambria\",\"serif\";\n\tcolor:#4F81BD;\n\tfont-weight:bold;}\np.msolistparagraphcxspfirst, li.msolistparagraphcxspfirst, div.msolistparagraphcxspfirst\n\t{mso-style-name:msolistparagraphcxspfirst;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\np.msolistparagraphcxspmiddle, li.msolistparagraphcxspmiddle, div.msolistparagraphcxspmiddle\n\t{mso-style-name:msolistparagraphcxspmiddle;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:0in;\n\tmargin-left:.5in;\n\tmargin-bottom:.0001pt;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\np.msolistparagraphcxsplast, li.msolistparagraphcxsplast, div.msolistparagraphcxsplast\n\t{mso-style-name:msolistparagraphcxsplast;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.5in;\n\tline-height:115%;\n\tfont-size:11.0pt;\n\tfont-family:\"Calibri\",\"sans-serif\";}\nspan.CodeChar\n\t{mso-style-name:\"Code Char\";\n\tmso-style-link:Code;\n\tfont-family:\"Lucida Console\";\n\tcolor:#EEEDF0;\n\tbackground:#012456;}\np.Code, li.Code, div.Code\n\t{mso-style-name:Code;\n\tmso-style-link:\"Code Char\";\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:12.0pt;\n\tmargin-left:.75in;\n\tline-height:115%;\n\tbackground:#012456;\n\tfont-size:8.0pt;\n\tfont-family:\"Lucida Console\";\n\tcolor:#EEEDF0;}\np.msopapdefault, li.msopapdefault, div.msopapdefault\n\t{mso-style-name:msopapdefault;\n\tmargin-top:0in;\n\tmargin-right:0in;\n\tmargin-bottom:10.0pt;\n\tmargin-left:.75in;\n\tline-height:115%;\n\tfont-size:12.0pt;\n\tfont-family:\"Times New Roman\",\"serif\";}\n.MsoChpDefault\n\t{font-size:10.0pt;}\n@page Section1\n\t{size:8.5in 11.0in;\n\tmargin:1.0in 1.0in 1.0in 1.0in;}\ndiv.Section1\n\t{page:Section1;}\n--><\/p>\n<p>Did you realize that Format-Table had a parameter -GroupBy?&nbsp; This tells Format-Table to generate a series of tables instead of a single table.&nbsp; The best way to get this in focus is to show an example.&nbsp; <\/p>\n<blockquote>\n<p>For the purposes of this blog entry, I&#8217;m going to use the aliases GSV for Get-Service and FT for Format-Table.&nbsp; Also, I don&#8217;t want too much data for the examples so I&#8217;m going to leverage the fact that GSV supports wildcards and specify s[p-z]*&nbsp; which says give me all the services that start with &#8220;s&#8221; and whose second character is between &#8220;p&#8221; and &#8220;z&#8221; inclusive.&nbsp; There is nothing special about this, I just did some quick experimentation and that seemed to produce a reasonable dataset for this blog (and it allows me to show off wildcarding in GSV \ud83d\ude42 ).<\/p>\n<\/blockquote>\n<p>First let&#8217;s look at the output of GSV and then explore what additional information is available:<\/p>\n<p class=\"Code\">PS&gt; gsv s[p-z]* |ft<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>Spooler<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Print Spooler<br \/>Stopped<span>&nbsp; <\/span>SQLBrowser<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SQL Server Browser<br \/>Stopped<span>&nbsp; <\/span>SQLWriter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SQL Server VSS Writer<br \/>Running<span>&nbsp; <\/span>SRUserService<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>IT Connection Manager<br \/>Running<span>&nbsp; <\/span>SSDPSRV<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SSDP Discovery<br \/>Running<span>&nbsp; <\/span>stisvc<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Windows Image Acquisition (WIA)<br \/>Stopped<span>&nbsp; <\/span>swprv<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Microsoft Software Shadow Copy Prov&#8230;<br \/>Running<span>&nbsp; <\/span>SysMain<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Superfetch<\/p>\n<p>PS&gt; gsv s[p-z]* |Get-Member -MemberType Property<\/p>\n<p><span>&nbsp;&nbsp; <\/span>TypeName: System.ServiceProcess.ServiceController<\/p>\n<p>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>MemberType Definition<br \/>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<br \/>CanPauseAndContinue Property<span>&nbsp;&nbsp; <\/span>System.Boolean CanPauseAndContinue {get;}<br \/>CanShutdown<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.Boolean CanShutdown {get;}<br \/>CanStop<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.Boolean CanStop {get;}<br \/>Container<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.ComponentModel.IContainer Containe&#8230;<br \/>DependentServices<span>&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.ServiceProcess.ServiceController[]&#8230;<br \/>DisplayName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.String DisplayName {get;set;}<br \/>MachineName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.String MachineName {get;set;}<br \/>ServiceHandle<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.Runtime.InteropServices.SafeHandle&#8230;<br \/>ServiceName<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.String ServiceName {get;set;}<br \/>ServicesDependedOn<span>&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.ServiceProcess.ServiceController[]&#8230;<br \/>ServiceType<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.ServiceProcess.ServiceType Service&#8230;<br \/>Site<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>Property<span>&nbsp;&nbsp; <\/span>System.ComponentModel.ISite Site {get;set;}<br \/>Status<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Property<span>&nbsp;&nbsp; <\/span>System.ServiceProcess.ServiceControllerSt&#8230;<\/p>\n<p>&nbsp;<\/p>\n<p>Notice that the ServiceController objects emitted by Get-Service (GSV) contain the field <strong>ServiceType <\/strong>.&nbsp; Let&#8217;s do this again but this time have Format-Table Group the services by ServiceType:<\/p>\n<p class=\"Code\">PS&gt; gsv s[p-z]* |ft -GroupBy ServiceType<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32OwnProcess, InteractiveProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>Spooler<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Print Spooler<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32OwnProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Stopped<span>&nbsp; <\/span>SQLBrowser<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SQL Server Browser<br \/>Stopped<span>&nbsp; <\/span>SQLWriter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SQL Server VSS Writer<br \/>Running<span>&nbsp; <\/span>SRUserService<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>IT Connection Manager<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32ShareProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>SSDPSRV<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SSDP Discovery<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32OwnProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>stisvc<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Windows Image Acquisition (WIA)<br \/>Stopped<span>&nbsp; <\/span>swprv<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Microsoft Software Shadow Copy Prov&#8230;<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32ShareProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp;&nbsp;<\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>SysMain<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Superfetch<\/p>\n<p>Now you get a&nbsp;series of tables.&nbsp; <\/p>\n<p>But wait. &nbsp;Take a&nbsp;close&nbsp;look at those tables.&nbsp; Notice that you have 2 tables for both Win32ShareProcess and Win32OwnProcess.&nbsp; The reason for that is that is that Format-Table (ft) is STREAM-ORIENTED.&nbsp; By that I mean that it gets an object and processes it and then moves on to the next.&nbsp; It does that so that it doesn&#8217;t have to keep all the objects in memory.&nbsp; When it is done with the object, it is done with the object.&nbsp; <\/p>\n<blockquote>\n<p>The only exception to this is when you specify -AutoSize&nbsp;. This tells Format-Table to collect all the objects and calculate the optimal column widths.<\/p>\n<\/blockquote>\n<p>So the results we got are not quite what we wanted.&nbsp; The solution is to sort the object stream prior to sending it to Format-Table (Yes yes yes &#8211; let me preempt the question &#8211; given these semantics we could have chosen to do the sort in Format-Table.&nbsp; The reason we didn&#8217;t is that it would be wasteful if the stream was already properly sorted).&nbsp; So lets see what that looks like:<\/p>\n<p class=\"Code\">PS&gt; gsv s[p-z]* |Sort ServiceType |ft -GroupBy ServiceType<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32OwnProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Stopped<span>&nbsp; <\/span>SRUserService<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>IT Connection Manager<br \/>Running<span>&nbsp; <\/span>stisvc<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Windows Image Acquisition (WIA)<br \/>Stopped<span>&nbsp; <\/span>swprv<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Microsoft Software Shadow Copy Prov&#8230;<br \/>Stopped<span>&nbsp; <\/span>SQLBrowser<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SQL Server Browser<br \/>Stopped<span>&nbsp; <\/span>SQLWriter<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SQL Server VSS Writer<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32ShareProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running <span>&nbsp;<\/span>SysMain<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Superfetch<br \/>Running<span>&nbsp; <\/span>SSDPSRV<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SSDP Discovery<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32OwnProcess, InteractiveProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>Spooler<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Print Spooler<\/p>\n<p>Now that is much better but notice that within a table, things are not sorted by Status.&nbsp;&nbsp;No problem.&nbsp; Did you realize that sort can do a multi-key sort?&nbsp; After we sort by Status, we&#8217;ll figure out that we also want it sorted by Name as well so let&#8217;s do it all at once shall we?<\/p>\n<p class=\"Code\">PS&gt; gsv s[p-z]* |Sort ServiceType,Status,Name |ft -GroupBy ServiceType<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32OwnProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Stopped<span>&nbsp; <\/span>SQLBrowser<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SQL Server Browser<br \/>Stopped<span>&nbsp; <\/span>SQLWriter<span>&nbsp;&nbsp;&nbsp;&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>SQL Server VSS Writer<br \/>Stopped<span>&nbsp; <\/span>SRUserService<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>IT Connection Manager<br \/>Stopped<span>&nbsp; <\/span>swprv<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Microsoft Software Shadow Copy Prov&#8230;<br \/>Running<span>&nbsp; <\/span>stisvc<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Windows Image Acquisition (WIA)<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32ShareProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp; <\/span><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;-<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>SSDPSRV<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>SSDP Discovery<br \/>Running<span>&nbsp; <\/span>SysMain<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Superfetch<\/p>\n<p><span>&nbsp;&nbsp; <\/span>ServiceType: Win32OwnProcess, InteractiveProcess<\/p>\n<p>Status<span>&nbsp;&nbsp; <\/span>Name<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>DisplayName<br \/>&#8212;&#8212;<span>&nbsp;&nbsp; <\/span>&#8212;- <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span>&#8212;&#8212;&#8212;&#8211;<br \/>Running<span>&nbsp; <\/span>Spooler<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Print Spooler<\/p>\n<p>Cheers!&nbsp;<\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows PowerShell\/MMC 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>Did you realize that Format-Table had a parameter -GroupBy?&nbsp; This tells Format-Table to generate a series of tables instead of a single table.&nbsp; The best way to get this in focus is to show an example.&nbsp; For the purposes of this blog entry, I&#8217;m going to use the aliases GSV for Get-Service and FT for [&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":[],"class_list":["post-8811","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Did you realize that Format-Table had a parameter -GroupBy?&nbsp; This tells Format-Table to generate a series of tables instead of a single table.&nbsp; The best way to get this in focus is to show an example.&nbsp; For the purposes of this blog entry, I&#8217;m going to use the aliases GSV for Get-Service and FT for [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8811","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=8811"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8811\/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=8811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=8811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=8811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}