title: How to determine the binding order of network interfaces on Windows using .NET?
body: <p>I'm trying to find the magical answer to the "what's the primary IP address" of a system. My research has determined that the answer to "best" means this:</p>
  
  <ol>
  <li>Look at [system.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() for interfaces with default gateways assigned. If you only find one, then you are done.</li>
  <li>If there's more than one, you have to look at the routing table for the one with the lowest metric (look at the 0.0.0.0 network entries).</li>
  <li>In case of a tie in the metric, the adapter with the lowest binding order wins.</li>
  </ol>
  
  <p>My question is: how do you determine the binding order using .NET? I've seen a <a href="http://www.peetersonline.nl/index.php/powershell/check-nic-bind-order/" rel="nofollow noreferrer">solution</a> that looks at the registry and that's alright, but I was hoping for a prettier interface.</p>
  
  <p>Bonus points for PowerShell samples as that's my language of choice. :)</p>