title: In PowerShell, what's the best way to join two tables into one?
body: <p>I'm fairly new to PowerShell, and am wondering if someone knows of any better way to accomplish the following example problem.</p>
  <p>I have an array of mappings from IP address to host-name. This represents a list of active DHCP leases:</p>
  <pre><code>PS H:\&gt; $leases
  
  IP                    Name
  --                    ----
  192.168.1.1           Apple
  192.168.1.2           Pear
  192.168.1.3           Banana
  192.168.1.99          FishyPC
  </code></pre>
  <p>I have another array of mappings from MAC address to IP address.  This represents a list of IP reservations:</p>
  <pre><code>PS H:\&gt; $reservations
  
  IP                    MAC
  --                    ---
  192.168.1.1           001D606839C2
  192.168.1.2           00E018782BE1
  192.168.1.3           0022192AF09C
  192.168.1.4           0013D4352A0D
  </code></pre>
  <p>For convenience, I was able to produce a third array of mappings from MAC address to IP address and host name using the following code. The idea is that <code>$reservations</code> should get a third field, &quot;Name&quot;, which is populated whenever there's a matching &quot;IP&quot; field:</p>
  <pre><code>$reservations = $reservations | foreach {
      $res = $_
      $match = $leases | where {$_.IP -eq $res.IP} | select -unique
      if ($match -ne $NULL) {
          &quot;&quot; | select @{n=&quot;IP&quot;;e={$res.IP}}, @{n=&quot;MAC&quot;;e={$res.MAC}}, @{n=&quot;Name&quot;;e={$match.Name}}
      }
  }
  </code></pre>
  <p>The desired output is something like this:</p>
  <pre><code>PS H:\&gt; $ideal
  
  IP                    MAC                 Name
  --                    ---                 ----
  192.168.1.1           001D606839C2        Apple
  192.168.1.2           00E018782BE1        Pear
  192.168.1.3           0022192AF09C        Banana
  192.168.1.4           0013D4352A0D
  </code></pre>
  <p>Is there any better way of doing this?</p>