title: command line to determine which Ethernet interface is in use
body: <p>I have a script that I wrote to help to configure computers after they are deployed. The script does things like sets computer name, enable's BitLocker, etc. The one thing that I am struggling with is the setting of an IP address. The computers that I am using (servers to be specific) have 4 NIC ports and they are named Local area connection and Local area connection 2-4. The problem is that the technicians that deploy these servers don't always plug into the same port, and additionally the deployment image doesn't always assign the ethernet net local area connection to the NIC port 1.</p>
  
  <p>Here is a copy of the script that I have, which works perfectly if only a single NIC port is enabled.  What I need to do is pipe the output of the Local Area Connection name that has an IP address (because DHCP already exists) into a variable that I can put into my <code>netsh</code> command.</p>
  
  <p>Current code in place</p>
  
  <pre><code>:IPADDRESS
  @echo Would you like static or DHCP?
  @echo press 1 for static
  @echo press 2 for dhcp
  Choice /C:12 /N /M "?:"
  IF ERRORLEVEL 2 GOTO IPDHCP
  IF ERRORLEVEL 1 GOTO IPSTATIC
  
  :IPSTATIC
  set /P _IPADDR=Please enter IP address:
  set /p _Subnet=Please enter Subnet:
  set /p _DefaultGateway=Please Enter Default Gateway:
  
  netsh interface ip set address name="Local Area Connection 2" static %_IPADDR% %_Subnet% %_DefaultGateway%
  goto START
  
  :IPDHCP
    netsh interface ip set address "Local Area Connection 2" dhcp
   goto START
  
   :disipaddr
    netsh interface ip show config name="Local Area Connection 2"
  </code></pre>
  
  <p>The name "Local Area Connection 2" is the part that changes from build to build. So that is the part that I need to isolate. I am fairly certain that the for <code>/p</code> and using it against either <code>ipconfig /all</code> or netsh  interface ip show config would be the correct way to go.</p>
  
  <p>Thank you in advance for all of the help.  </p>