Rambeaux007
IS-IT--Management
Hello,
I am trying to create a script that will only configure the DNS suffixes for a specific adapter. Unfortunately I can only utilize the NetconnectionID name with happens to have a space in the name. Can someone point me in the right direction?
Thanks!!
On Error Resume Next
strComputer = ","
arrNewDNSSuffixSearchOrder = Array("domainA.net", "domainB.net",_
"domainC.net")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE NetconnectionID = 'NIC One'")
For Each objNicConfig In colNicConfigs
strDNSHostName = objNicConfig.DNSHostName
Next
WScript.Echo VbCrLf & "DNS Host Name: " & strDNSHostName
For Each objNicConfig In colNicConfigs
WScript.Echo VbCrLf & _
" Network Adapter " & objNicConfig.Index & VbCrLf & _
" " & objNicConfig.Description & VbCrLf & _
" DNS Domain Suffix Search Order - Before:"
If Not IsNull(objNicConfig.DNSDomainSuffixSearchOrder) Then
For Each strDNSSuffix In objNicConfig.DNSDomainSuffixSearchOrder
WScript.Echo " " & strDNSSuffix
Next
End If
Next
WScript.Echo VbCrLf & String(80, "-")
Set objNetworkSettings = _
objWMIService.Get("Win32_NetworkAdapterConfiguration")
intSetSuffixes = _
objNetworkSettings.SetDNSSuffixSearchOrder(arrNewDNSSuffixSearchOrder)
If intSetSuffixes = 0 Then
WScript.Echo VbCrLf & "Replaced DNS domain suffix search order list."
ElseIf intSetSuffixes = 1 Then
WScript.Echo VbCrLf & "Replaced DNS domain suffix search order list." & _
VbCrLf & " Must reboot."
Else
WScript.Echo VbCrLf & "Unable to replace DNS domain suffix " & _
"search order list."
End If
WScript.Echo VbCrLf & String(80, "-")
Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration NetconnectionID = 'NIC One'")
For Each objNicConfig In colNicConfigs
WScript.Echo VbCrLf & _
" Network Adapter " & objNicConfig.Index & VbCrLf & _
" " & objNicConfig.Description & VbCrLf & _
" DNS Domain Suffix Search Order - After:"
If Not IsNull(objNicConfig.DNSDomainSuffixSearchOrder) Then
For Each strDNSSuffix In objNicConfig.DNSDomainSuffixSearchOrder
WScript.Echo " " & strDNSSuffix
Next
End If
Next
I am trying to create a script that will only configure the DNS suffixes for a specific adapter. Unfortunately I can only utilize the NetconnectionID name with happens to have a space in the name. Can someone point me in the right direction?
Thanks!!
On Error Resume Next
strComputer = ","
arrNewDNSSuffixSearchOrder = Array("domainA.net", "domainB.net",_
"domainC.net")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE NetconnectionID = 'NIC One'")
For Each objNicConfig In colNicConfigs
strDNSHostName = objNicConfig.DNSHostName
Next
WScript.Echo VbCrLf & "DNS Host Name: " & strDNSHostName
For Each objNicConfig In colNicConfigs
WScript.Echo VbCrLf & _
" Network Adapter " & objNicConfig.Index & VbCrLf & _
" " & objNicConfig.Description & VbCrLf & _
" DNS Domain Suffix Search Order - Before:"
If Not IsNull(objNicConfig.DNSDomainSuffixSearchOrder) Then
For Each strDNSSuffix In objNicConfig.DNSDomainSuffixSearchOrder
WScript.Echo " " & strDNSSuffix
Next
End If
Next
WScript.Echo VbCrLf & String(80, "-")
Set objNetworkSettings = _
objWMIService.Get("Win32_NetworkAdapterConfiguration")
intSetSuffixes = _
objNetworkSettings.SetDNSSuffixSearchOrder(arrNewDNSSuffixSearchOrder)
If intSetSuffixes = 0 Then
WScript.Echo VbCrLf & "Replaced DNS domain suffix search order list."
ElseIf intSetSuffixes = 1 Then
WScript.Echo VbCrLf & "Replaced DNS domain suffix search order list." & _
VbCrLf & " Must reboot."
Else
WScript.Echo VbCrLf & "Unable to replace DNS domain suffix " & _
"search order list."
End If
WScript.Echo VbCrLf & String(80, "-")
Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration NetconnectionID = 'NIC One'")
For Each objNicConfig In colNicConfigs
WScript.Echo VbCrLf & _
" Network Adapter " & objNicConfig.Index & VbCrLf & _
" " & objNicConfig.Description & VbCrLf & _
" DNS Domain Suffix Search Order - After:"
If Not IsNull(objNicConfig.DNSDomainSuffixSearchOrder) Then
For Each strDNSSuffix In objNicConfig.DNSDomainSuffixSearchOrder
WScript.Echo " " & strDNSSuffix
Next
End If
Next