title: Count, Sort and Group-By in Powershell
body: <p>Are there any cool cmdlets that will help me do the following? 
  I want something in Powershell that is as simple as doing the same in SQL: </p>
  
  <pre class="lang-sql prettyprint-override"><code>select RootElementName , count(*) from Table
  group by RootElementName 
  order by RootElementName 
  </code></pre>
  
  <p>I'm all XML files in a directory, finding the root element of each XML file.</p>
  
  <pre class="lang-cs prettyprint-override"><code>$DirectoryName = "d:\MyFolder\"
  $AllFiles = Get-ChildItem $DirectoryName -Force 
  foreach ($Filename in $AllFiles) 
  {
       $FQFilename = $DirectoryName + $Filename
       [xml]$xmlDoc = Get-Content $FQFilename
       $rootElementName = $xmlDoc.SelectSingleNode("/*").Name; 
       Write-Host $FQFilename $rootElementName 
  }
  </code></pre>
  
  <p>Desired Result: </p>
  
  <pre class="lang-none prettyprint-override"><code>RootName   Count 
  --------   -----
  Root1      15 
  MyRoot     16 
  SomeRoot   24 
  </code></pre>
  
  <p>I know I could could either create two arrays, or an array of objects, store the root elements in the array, and do the counts all using typical code, was just hoping that this new language might have something built-in that I haven't discovered yet. </p>
  
  <p>Could I pipe the "Write-Host $FQFilename $rootElementName " to something that would behave something to the SQL I referred to above? </p>