I am trying to build a script to get and save in a variable the current DNS setting of a non-DHCP enable client. Once I have gotten this variable I would then need to place it back into client with the addition of a current and correct DNS entry. I need to keep the old entrys because they do not know if they are there for a reason or not. I have been able to build the part that puts the entry back, but it over writes the current entries. I am having difficulties trying to get the old DNS entries into a variable to use later. I am relatively new to scripting and have only made simple scripts or just modified ones to suit my needs. Any and all help would be greatly appreciated. Scripts are as follows:
DNS Entry Insertion script:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE")
For Each objNetCard in colNetCards
If objNetCard.DHCPEnabled = True Then
object.Skip(3)
Else
arrDNSServers = Array("***.***.***.***", "***.***.***.***")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
End If
Next
I have been able to get the current DNS entries to echo to the screen, but have no idea how to get them into a variable. Here is what I have for echoing them to the screen:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
WScript.Echo " " & objAdapter.DNSServerSearchOrder(i)
Next
End If
Next
Thank you in Advance to anyone who can help on this matter.
Sean P. Mehrlander
DNS Entry Insertion script:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = TRUE")
For Each objNetCard in colNetCards
If objNetCard.DHCPEnabled = True Then
object.Skip(3)
Else
arrDNSServers = Array("***.***.***.***", "***.***.***.***")
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
End If
Next
I have been able to get the current DNS entries to echo to the screen, but have no idea how to get them into a variable. Here is what I have for echoing them to the screen:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
WScript.Echo " " & objAdapter.DNSServerSearchOrder(i)
Next
End If
Next
Thank you in Advance to anyone who can help on this matter.
Sean P. Mehrlander