Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBSCRIPT to capture DHCP and change to static

Status
Not open for further replies.

lpb71

Technical User
Mar 10, 2004
57
GB
Does anyone have a script that can read the DHCP info from a PC and change to be a static address. I am trying to remove DHCP from certain sites and want to make the visit as easy as possible.
 
Hi There

Change the IP details and Computer name to suit

The Computer name currently has a . in it which means local machine. Its worth leaving this to test on your local PC first, then change after.

BTW, Keep all the quotes when changing the details.

Hope it helps




' Specidfy the computerName (. means local)
strComputer = "."

' Bind to the computers WMI
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

' Bind to the network card that has IP enabled
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

' Set our IP Details etc.
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.1")
strGatewayMetric = Array(1)

arrDNSServers = Array("192.168.1.100", "192.168.1.200")
' or use this if only 1 DNS server
' arrDNSServers = Array("192.168.1.100")

' Loop the properties of the network adapter and make the changes
For Each objNetAdapter in colNetAdapters

' Set IP, Subnet and gateway
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If

' Set the DNS Domain
errDNSname = objNetAdapter.SetDNSDomain("fabrikam.com")
If errDNSname = 0 Then
WScript.Echo "The DNS name has been changed."
Else
WScript.Echo "The DNS name could not be changed."
End If

' Set the DNS Servers
errDNSservers = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errDNSservers = 0 Then
WScript.Echo "The DNS server has been changed."
Else
WScript.Echo "The DNS server could not be changed."
End If

Next



Regards
Krystian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top