title: Combining Group-Object and ForEach-Object?
body: <p>I'm developing a cmdlet called <code>Merge-Xsd</code> that can merge similar XML schemas. It takes a list of paths, loads the schemas, merges them, and produces an <code>XMLDocument</code> as output.</p>
  
  <p>All schemas of a particular file name are considered "similar", and so what I'm doing is getting all of the child items in a particular directory structure, grouping them according to the file name, and then trying to pass them to my custom cmdlet.</p>
  
  <p>Grouping them is easy:</p>
  
  <pre><code>$grouping = Get-ChildItem -Recurse -Filter *.xsd |
      Group-Object -Property Name -AsHashTable -AsString
  </code></pre>
  
  <p>However, processing them as part of the same pipeline is not. I've gotten as close as this:</p>
  
  <pre><code>$grouping.Keys |
      ForEach-Object { ($grouping[$_] |
          Select-Object -ExpandProperty FullName | Merge-Xsd).Save("C:\Out\$_") }
  </code></pre>
  
  <p>But what I'd <em>really</em> like to be able to do is use <code>ForEach-Object</code> directly after <code>Group-Object</code> to iterate over each group item, thus eliminating the need for the separate <code>$grouping</code> variable.</p>
  
  <p>How can I use <code>ForEach-Object</code> to get the key/value pair while keeping each invocation of <code>Merge-Xsd</code> scoped to that particular key/value pair?</p>
  
  <p><strong>20150224 UPDATE:</strong></p>
  
  <p>The <code>Merge-Xsd</code> option set is extremely basic:</p>
  
  <pre><code>NAME
      Merge-Xsd
  
  SYNTAX
      Merge-Xsd [-Path] &lt;string[]&gt;  [&lt;CommonParameters&gt;]
  </code></pre>
  
  <p>It is really just intended for throwing a bunch of files at it in one go and having them merged into a single output, which is an <code>XmlDocument</code>. (I modeled the output off of <code>ConvertTo-Xml</code>.)</p>