netsh set IP address adaptor name conflict - batch-file

I use the following netsh command when setting the IP address of the LAN Adaptor within a batch file.
netsh int ipv4 set address name="Local Area Connection" source=static address=10.000.0.1 mask=255.255.255.0 gateway=none
I have recently encountered an issue where the batch-file was run on a different system and this has failed to work (returning Element Not Found), I found the cause of the issue to be the adaptor was labelled 'Ethernet'.
This works fine providing the adaptor is labelled as 'Local Area Connection' and the easy fix is to rename the adaptor.
However i would like a solution where it isnt required to rename and the command works on any system irrelevant of how the LAN Adaptor is labelled on that system.
Is this possible?

Related

Batch script to enable a disabled network adapter with different names

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.
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 ipconfig /all command which I have been using it to obtain the adapter name (e.g Wi-Fi, Wi-Fi 2, etc.) thus the netsh command gave the error due to the varible being invalid.
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 netsh interface set interface name="Wi-Fi" admin=enabled 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 ipconfig or wmic command. Thanks!
::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

How to force DHCP on all phyiscal ports, including Disconnected Media ports, with WMIC

Could anyone help me force all network adapters to be DHCP whether connected or disconnected.
I am relatively new and very novice in batch and I have been working on something to set fixed ipv4 details based on variable Ethernet adapter names. It has been cobbled together from other people's solutions to various problems on here. I am sure there are much more eloquent and elegant ways of doing this and happy to be pointed that way but I would like to try and figure this out.
The idea was to have a call batch script in the startup folder of a OOBE windows machine. Search the connected adapter, irrelevant of the name of said port, set the IP address as static and rest of the details were fixed. I wrote the batch in such a way as to create various IP profiles using variables to create the profile to set the fixed details i.e. a batch to write a batch
As an exercise I was thinking if I were to move the machine and plug in a different adapter on the same machine. How would I have a disconnected adapter with the IP address I want to use switch to DHCP. This would free up the address to search for connected adapter as per the rest of the script. This is where the script fails. I can have the connected adapter switch tp DHCP, disable and enable correctly.
WMIC NICConfig Where "IPEnabled='True' and DHCPEnabled='FALSE'" Call EnableDHCP
this works but only on the connected adapter.
But I am trying to flush out the IP address on the disconnected adapter to use on the connected adapter. So far I've tried
WMIC NICConfig Where NetConnectionID=7 Call EnableDHCP
returns a "Description = Invalid query"
WMIC NICConfig Where "PhysicalAdapter='True'" Call EnableDHCP
returns a "Description = Invalid query"
WMIC NICConfig Where "DHCPEnabled='FALSE'" Call EnableDHCP
returns {ReturnValue = 84;}; I thought this would search for adapters that were not DHCP and change to to be DHCP but I think the adapter has to be connected.
When I use
WMIC NICConfig Where "PhysicalAdapter='True'" Call /?
EnableDHCP looks to be an option but gives a "Description = Invalid query"
Is there a way to do what I am trying to do?
I can also post the entire script if anyone is interested in it but will leave it off until requested. Thanks in advance for any help.
I figured this out.
I was going about it the complete wrong way.
I was trying to clear all adapters fixed ip addresses by "forcing" the physical adapter to DCHP weather connected or disconnected.
But if I have had said
netsh int ip reset
wmic path win32_networkadapter where PhysicalAdapter=True call disable
wmic path win32_networkadapter where PhysicalAdapter=True call enable
This achieves what I want. This clears the IP, subnet and gateway. Sometimes the solution is much easier than expected.
Is there a way to clear the DNS information too for all physical adapters, without knowing their names, so that if IPV4 properties is open no information would be there?

disable ipv4 or ipv6 in local area connection - batch file

I have multiple NIC's some use IPv4 others IPV6, by using batch file I am trying to figure out how i can disable IP4 on the NICs that solely use IPV6 and also disable IPV6 on the NICs that use IPV4. currently performing this manually within NIC properties by un-ticking the box of IPv4 or IPv6.
It seems netsh is unable to do this - any ideas how this is possible?
You'll have to use nvspbind . Though it is not supported anymore is the only command line tool provided by MS capable to do this.
This for example should disable IPv6 on "Local Area Connection" :
nvspbind.exe /d "Local Area Connection" ms_tcpip6
And this is for IPv4
nvspbind.exe /d "Local Area Connection" ms_tcpip

Check Windows Network Interfaces and enable them if down with batch file

I am new to batch file/script...Anyway, on my Windows server, I have two interfaces:
Interface-1(Local Area Connection 2) has, say,
10.0.77.200/16 and configured with a default gateway
Interface-2(Local Area Connection 3) has, say,
10.0.50.200/30 and no default default gateway configured.
I am looking for a simple way to create a simple batch to check these 2 interfaces, if either one or both are down, I want the batch script to re-enable them automatically.
Thanks,
Lenna -
The netsh interface show interface command will return information about the state of the interfaces. Instead of checking to see if one is down, I would just recommend running the netsh interface set interface commands to enable them as it will be much easier and won't hurt anything:
netsh interface set interface name="Local Area Connection 2" admin = ENABLED
netsh interface set interface name="Local Area Connection 3" admin = ENABLED

Enable Disable XP WIFi using command line

Help me out to, Enable and Disable WIFI in my XP using Command Line.
Tried with:
netsh interface set interface name="Wireless Network Connection " admin=disabled
but it is showing, More data to display.
Also, "netsh interface show interface"
Does not display any Interface name.
Thanks in Advance.
That's command should work fine. Are you sure it's not disabled? is there really connection available with name Wireless Network Connection?
In your command, try replacing Wireless Network Connection with actual connection name like Local Area Connection
netsh interface set interface name="Local Area Connection" admin=disabled
Also if below command is not displaying then I doubt, you have any network interface configured. Check to make sure that.
netsh interface show interface
You can as well use the below alternative way to enable/disable a specific connection [Quoted from MS Community Answer]
Start elevated Command Prompt.
Get NIC list and index number:
wmic nic get name, index
Enable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call enable
Disable NIC with index number: (eg: 7)
wmic path win32_networkadapter where index=7 call disable

Resources