I'm trying to write a script that will involve modifying the IPv4 configuration of an interface. The interface may or may not already have any of the following configured:
- IP Address
- Subnet Mask
- Default Gateway
- DNS Servers
- WINS Servers
When my script is done, I want only the options that I have set to be configured. (e.g.: If I don't set a Gateway, DNS, or WINS server, then I want none to be configured.) I figure the easiest way to ensure this is to wipe out the existing configuration as much as I can and then build up just what I need.
Leaving the existing IP Address and Subnet Mask is okay, because these will definitely be overwritten every time. It looks fairly simple to delete DNS and WINS servers with
netsh interface ipv4 delete dns "LAN" all netsh interface ipv4 delete wins "LAN" all
My problem comes with deleting the gateway. It seems that every
netsh command that is used to modify the default gateway requires the current IP address as a parameter. However, this will not always be something that is known. Is there not a way to use
netsh to just delete all the gateways configured for an interface, without specifying the IP?