April 2004
Beginner
416 pages
11h 3m
English
After your script can connect to Active Directory and return a recordset of computer names, you’re ready to use WMI to convert the machines from static IP addresses to DHCP-assigned addresses. You scrounge around and come up with a script that uses WMI to turn on DHCP. This script, called EnableDHCP.vbs, is shown here:
Target = "."
Set oWMIService = GetObject("winmgmts:\\" & Target & "\root\cimv2")
Set colNetAdapters = oWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each oNetAdapter In colNetAdapters
errEnable = oNetAdapter.EnableDHCP()
If errEnable = 0 Then
WScript.Echo "DHCP has been enabled."
Else
WScript.Echo "DHCP could not be enabled."
End If
NextRead now
Unlock full access