Boswell's Q&A

Don't Give Me Any Static

How to automate the process of modifying a slew of statically mapped WINS servers.

Readers: I'm feeling a bit red-faced after last week's Q&A. If you recall, a reader had a problem with a USB thumb drive. He saw the contents of a mapped drive when he should have seen the contents of the thumb drive. I didn't know the cause so I advised dragging out a deep diagnostic tool called Winobj http://www.sysinternals.com/ntw2k/freeware/winobj.shtml and other complicated things to look for the source of the problem. I also asked for help.

Well, I received many, many replies from all around the world telling me that I had made the problem much too complicated. It turns out that the removable drive was simply taking the next available drive letter and "stepping on" an existing network drive mapping.

Here are the Admin All Stars who wrote in with the solution to the USB thumb drive content problem. Thanks to all of you!

Admin All Stars
Adrian Brown Jerry Ammann
Alberto Luna John Chambers
Alfonso Rodriguez Joris Desimpelaere
Anand PV Joshua Stein
Carson Wells Michael Dreisbaugh
Christopher Everett Ross Lane
Craig Tanson Steve Graupner
Dave Guibord Steve Ritter
Dereck Drodge Stewart Johnston
James Swayze  

The first respondent was Michael Dreisbaugh, and he won a highly coveted MCPMag ball cap.

Now for this question from an anonymous reader:

We're installing a couple of new WINS servers and now I face the task of modifying the WINS information in 150 servers with static TCP/IP configuration. Any suggestions how to automate this?

Get Help from Bill

Got a Windows or Exchange question or need troubleshooting help? Or maybe you want a better explanation than provided in the manuals? Describe your dilemma in an e-mail to Bill at mailto:[email protected]; the best questions get answered in this column.

When you send your questions, please include your full first and last name, location, certifications (if any) with your message. (If you prefer to remain anonymous, specify this in your message but submit the requested information for verification purposes.)

I have a couple of methods that I've used when making this sort of global change to server IP settings. To be honest, though, I like the "Just Say No" approach. Rather than change the statically mapped TCP/IP settings on the servers, just configure the network interface to use DHCP. Then you can change the WINS entries (or DNS, for that matter) in the DHCP scope options and just wait for the clients to renew their addresses to get the new settings.

"But wait," you say, "How will my clients find the servers if the server's IP addresses keep changing?"

Well, Windows 2000 and Windows Server 2003 servers will dynamically update their IP addresses in DNS and in WINS, so you don't have a problem in that respect.

But, you might have NT servers or Samba servers that don't dynamically update DNS. In that case, you could use a feature in Windows DHCP to update a DHCP client's A and PTR records in DNS when leasing an address.

Also, all your work processes must use DNS names rather than static IP addresses. If you have a developer or fellow admin who embedded a static address in some code or a configuration table, then you’ll be spending a while doing some debugging.

If you really don't want your servers' IP addresses to change, but you still want the flexibility to use DHCP scope options to control TCP/IP settings, you can reserve the server's lease in DHCP. This reservation uses the MAC address of the server's NIC as a unique identifier. If a server has multiple NICs, you can use multiple reservations.

In the end, you may decide that DHCP just isn't an option for your servers and you want to change the static settings remotely. Even if you do want to change over to DHCP, you face the job of changing the configuration for every server.

TCP/IP settings are stored in the Registry, but changing them turns out to be something of a trick because each interface stores its parameters under a key with a unique ID number. Here's an example:

HKEY_LOCAL_MACHINE\system\currentcontrolset\services\tcpip\
parameters\interfaces\{5D041A41-AEC3-4E47-9DF1-D612BCB0DCB4}
EnableDHCP REG_DWORD 0x0
NameServer REG_SZ 10.0.0.254
Domain REG_SZ company.com
RegistrationEnabled REG_DWORD 0x1
RegisterAdapterName REG_DWORD 0x1

To change the settings without knowing the UID, you can use Windows Management Instrumentation (WMI). Here's a brief VBScript example that takes the server names from a file called "serverlist.txt" and uses it to enable DHCP on the active network interface:

Set fso = CreateObject("Scripting.FileSystemObject")
Set fh = fso.OpenTextFile("c:\scripts\serverlist.txt",1)

Do While Not fh.AtEndOfStream
WScript.Echo vbCrLf & String(20,"*")
computerName = fh.ReadLine()
Set wmiObj = GetObject(
"winmgmts:{impersonationLevel=impersonate}!\\"
& computerName & "\root\cimv2")
Set nicList = wmiObj.ExecQuery (
"SELECT * FROM Win32_NetworkAdapterConfiguration
WHERE IPEnabled = True")

For Each nic In nicList
If nic.DHCPEnabled Then
WScript.Echo "DHCP already enabled on "
& nic.Caption & " for " & computerName & "."
Else
nic.EnableDHCP
WScript.Echo "Enabled DHCP on " & nic.Caption
& " for " & computerName & "."
End If
Next
Loop

Whoa! You'll want to do some experimenting before you unleash this script on your production network. For example, you might have servers with two live interfaces, one for the production side and one for backup. This script would convert both interfaces to DHCP and the backups will fail. You can avoid this by only applying the DHCPUpdate method to interfaces where the first couple of octets in the nic.IPAddress property match the production network.

There are similar potential problems with VMware virtual adapter settings, VPN endpoint settings, and others. Choose your targets carefully.

If you have static settings and just want to change the WINS properties, you can use a similar script to access the Win32_NetworkAdapterConfiguration properties of the interface. then change these two properties:

  • WINSPrimaryServer
  • WINSSecondaryServer

If you want to see all the WMI properties, use WMIC with the following syntax:

wmic path win32_networkadapterconfiguration get * /format:list

To use WMI to manage NT servers, you'll need to install the most current WBEM drivers on the servers. The WBEM files for NT4 are included in the WMICore download at http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=AFE41F46-E213-4CBF-9C5B-FBF236E0E875.

Until next week!

About the Author

Contributing Editor Bill Boswell, MCSE, is the principal of Bill Boswell Consulting, Inc. He's the author of Inside Windows Server 2003 and Learning Exchange Server 2003 both from Addison Wesley. Bill is also Redmond magazine's "Windows Insider" columnist and a speaker at MCP Magazine's TechMentor Conferences.

comments powered by Disqus
Most   Popular