Automate Network Adapter Configuration using NETSH

So I'm kind of lazy.  Not in the "sleep late and don't go to work" slacker way, I just don't like doing dull repetitive tasks if they can be automated in some way. As a rule if I have to do the same task more than a couple of times I'm writing a script (or getting someone else to do it).

During the years I worked as a consultant it was not uncommon to connect my laptop to several different networks in the same day. In some cases they were DHCP enabled so connection was easy. For others I would have to configure the network adapter manually. Ugh!

Enter the NETSH commands.  The NETSH command can be used to modify the network configuration on Windows 2000 and later computers. It's not the friendliest syntax to use but it is a real time saver once you learn to use it (I have noticed the version that ships with Vista seems almost intuitive). Listed below are sample script for using NETSH to set STATIC IP entries on an adapter and another script to set the adapter back to DHCP mode so the settings can be obtained automatically. The command syntax for Vista and XP are slight different due to the fact that Vista supports IPV6 natively so sample scripts for each OS are listed below. To use the code, paste it into a batch file and modify the "name=" to the name of the adapter in quotes and change the IP addresses.

VISTA - Static IP

netsh interface ipv4 set address name="Wireless Network Connection 2" source=static addr=192.168.0.100 mask=255.255.255.0 gateway=192.168.0.250 gwmetric=0
netsh interface ipv4 set dnsserver name="Wireless Network Connection 2" source=static addr=192.168.0.2 register=NONE
REM netsh interface ipv4 set wins name="Wireless Network Connection 2" source=static addr=155.217.27.9
REM OR if no WINS server
netsh interface ipv4 set winsserver name="Wireless Network Connection 2" source=dhcp
ipconfig /all

VISTA - DHCP

netsh interface ipv4 set address name="Wireless Network Connection 2" source=dhcp
netsh interface ipv4 set dnsserver name="Wireless Network Connection 2" source=dhcp
netsh interface ipv4 set winsserver name="Wireless Network Connection 2" source=dhcp
ipconfig /renew "Wireless Network Connection 2"
ipconfig /all

XP - Static IP

netsh interface ip set address name="BROADCOM" source=static addr=192.168.27.40 mask=255.255.255.224
netsh interface ip set address name="BROADCOM" gateway=192.168.27.33 gwmetric=0
netsh interface ip set dns name="BROADCOM" source=static addr=192.168.98.12 register=NONE
netsh interface ip set wins name="BROADCOM" source=static addr=none

XP - DHCP

netsh interface ip set address name="BROADCOM" dhcp
netsh interface ip set dns name="BROADCOM source = dhcp
netsh interface ip set wins name="BROADCOM" source=dhcp