title: Resolve-DnsName - Formatting and Error Catching
body: <p>I have a list of domains from which I need a list of name servers for each domain and the IP addresses of the name servers.</p>
  
  <p>Formatting / A better way?</p>
  
  <pre><code>Resolve-DnsName google.com -Type NS -DnsOnly | Select Name, NameHost, IP4Address
  
  Name           NameHost       IP4Address
  ----           --------       ----------
  google.com     ns1.google.com
  google.com     ns4.google.com
  ns4.google.com                216.239.38.10
  ns1.google.com                216.239.32.10
  </code></pre>
  
  <p>I've cut the result down a bit. I would like the IP Address to appear on the same line as the rest of the data. A quick google showed me how to add a hash to the existing object.</p>
  
  <pre><code>$dl = gc C:\domains.txt
  $result = $dl |
      Resolve-DnsName -Type NS -DnsOnly |
          Where { $_.IP4Address -like '' } |
          Select Name, NameHost, @{l="IPAddress";e={Resolve-DnsName google.com -Type A | Select -ExpandProperty IPAddress}}
  </code></pre>
  
  <p>So for the above, is this the 'correct / best way' or would you recommend something else.</p>
  
  <p>Secondly, some of the results fail with lots of red, the important bit of information that I'd like to capture is 'DNS name does not exist', 'DNS server failure', there are a couple of others. How do I catch the relevant error, I assume I can add it to an new hash 'column'. I can't think of a way to use a try, catch block in my code?</p>