title: PowerShell/Windows scripting: Get interface name containing a specified gateway IP
body: <p>I'm trying to build a Windows batch script that captures a network interface's name, based on its gateway IP, and then renames the interface. I'm having trouble capturing the interface name, which is a random string. In Windows, I can obtain the needed information by running a piped netsh command:</p>
  
  <pre><code>C:\Users\Administrator&gt;netsh interface ipv4 dump | findstr "nexthop=2.2.2.1"
  
  add route prefix=0.0.0.0/0 interface="Management" nexthop=2.2.2.1 publish=yes
  </code></pre>
  
  <p>How can I parse for the interface string, as displayed in the output?</p>
  
  <p>I've also tried to experiment in PowerShell using a combination of the following commands, but haven't had much luck. I would appreciate any assistance, or a nudge in the right direction.</p>
  
  <pre><code> get-wmiObject -Query "select NetConnectionID from Win32_NetworkAdapter"
   get-wmiObject -Query "select DefaultIPgateway from Win32_NetworkAdapterConfiguration"
  </code></pre>
  
  <p>EDIT: I've started experimenting with wmic. Given the DefaultIPGateway is part of nicConfig, and NetConnectionID is part of nic, is there anyway I can get this working?</p>
  
  <pre><code>wmic nic where "DefaultIPgateway=2.2.2.1" get NetConnectionID
  </code></pre>