title: Batch script to enable a disabled network adapter with different names
body: <p>I'm writing a script to revert the network settings back to default which is to switch back to DHCP on LAN and re-enable the wireless adapter. All these operations were done under the local admin rights privileges for all devices that I'm managing.</p>
  
  <p>While the switching over to DHCP from static works, the script was unable to re-enable the wireless adapter and showing "No more data is available". I had did a bit of troubleshooting and found out that the disabled wireless adapter is not reflected in the <code>ipconfig /all</code> command which I have been using it to obtain the adapter name (e.g Wi-Fi, Wi-Fi 2, etc.) thus the <code>netsh</code> command gave the error due to the varible being invalid.</p>
  
  <p>Here is the part of the code that's responsible for the re-enabling the wireless adapter back. I'm aware that if I were to enter the <code>netsh interface set interface name="Wi-Fi" admin=enabled</code> manually it works based on the adapter name that's taken on my test device. But however I can't hard-code the adapter name as it may not be the same for different devices. Do share if there's any other code for the first line that I might not be not aware of as I did many googling and it only came up with either for the <code>ipconfig</code> or <code>wmic</code> command. Thanks!</p>
  
  <pre><code>::Look for the Wi-Fi adapter name
  for /f "tokens=* delims=:" %%b in ('ipconfig ^| find /i "Wireless LAN adapter Wi-Fi"') do set wifiadaptername=%%b
  set wifiadaptername=%wifiadaptername:~21%
  set wifiadaptername=%wifiadaptername:~0,-1%
  
  ::Switch on Wi-Fi
  netsh interface set interface name="%wifiadaptername%" admin=enabled
  </code></pre>