Link to home
Start Free TrialLog in
Avatar of jashir101
jashir101

asked on

Add dns and win entries, dns suffixes and enabling NetBIOS over TCP/IP to a specific network adapter

Hi All,

I have the script which add dns and win entries, dns suffixes and enabling NetBIOS over TCP/IP. Howver, it will add all entires to all network adapters.
Can anyone please help me how to add all the entries to a specific NIC card?
I am attaching the script here.
Any assistance could offer would be greatly appreciated..
On Error Resume Next
 
strComputer = "."
arrDNSServerSearchOrder = Array("192.18.4.1", "192.18.18.8", "144.16.21.1", "144.12.12.1")
arrDNSDomainSuffixSearchOrder = Array("cre.dir.se.com", "s.dir.se.com", "w.dir.sa.com", "c.ta.com.se", "in.ea.com.au", "ext.d.do.com", "tea.com.sa", "corl.tea.c.sa", "t.com.sa")
 
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objNicConf = objWMIService.Get("Win32_NetworkAdapterConfiguration")

intEnableDNS = objNicConf.EnableDNS(strDNSHostName, strDNSDomain, _
 arrDNSServerSearchOrder, arrDNSDomainSuffixSearchOrder)
 
 
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each objNicConfig In colNicConfigs
  strDNSHostName = objNicConfig.DNSHostName
Next


On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colNetCards = objWMIService.ExecQuery _
    ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objNetCard in colNetCards
    strPrimaryServer = "192.18.61.1"
    strSecondaryServer = "192.18.10.5"
    objNetCard.SetWINSServer strPrimaryServer, strSecondaryServer
Next


strComputer = "."
 
Const DEFAULT = 0
Const ENABLED = 1
Const DISABLED = 2
' ------ END CONFIGURATION ---------

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
For Each nic In nics
  intNetBT = nic.SetTCPIPNetBIOS(ENABLED) 
Next

Open in new window

Avatar of jashir101
jashir101

ASKER

Guys,

Can anyone provide a soultion for this??
at line 48 is where you get the network cards.  You will need something more there to filter and get the specific card that you want.  

What attribute can you use to narrow down which card that you want to activate Netbios for?
We are using 3 NIC cards here..suppose for example.

here we are using ADN network, NAS network

I want to add those entries to ADN network, so pls help me....
Here is some code you can replace lines 50-52.

You need some attribute to find the NIC that you want to edit.  So, I chose to use the Default Gateway setting on the NIC as my search attribute.
My example will change the NETBIOS settting (ENABLED) for any NIC with the Default Gateway set to 192.168.33.1


For Each nic In nics  
  if Not isNull(nic.DefaultIPGateway) then
    For x = 0 to UBound(nic.DefaultIPGateway)
       if nic.DefaultIPGateway(x) = "192.168.33.1" then
           intNetBT = nic.SetTCPIPNetBIOS(ENABLED)  
       end if
    Next
  end if
Next
thanks for your help chakko..

what i mean is i want to add dns and wins entries to a specific adapter, not enabling netbios over tcp/ip.

We are using 3 nics here..i want to add those to a adn(nic card name) to those entries.

Can u make a script whether it will prompt to ask "which network card do u want those entries?"


Try this.   You need to replace the part that says Put_your_domain.local   with your domain

The script will popup a message based on the 'friendly' name of your Network connection.


---------------------------------------------------------------------------


strComputer = "."
 
Const DEFAULT = 0
Const ENABLED = 1
Const DISABLED = 2


arrDNSServerSearchOrder = Array("192.18.4.1", "192.18.18.8", "144.16.21.1", "144.12.12.1")
arrDNSDomainSuffixSearchOrder = Array("cre.dir.se.com", "s.dir.se.com", "w.dir.sa.com", "c.ta.com.se", "in.ea.com.au", "ext.d.do.com", "tea.com.sa", "corl.tea.c.sa", "t.com.sa")
strWINSPrimaryServer = "192.18.61.1"
strWINSSecondaryServer = "192.18.10.5"


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

Set nics2 = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NetEnabled=True")


For Each Card in nics2
     nicName = Card.NetConnectionID
     Answer = MsgBox("Set this NIC card?" & nicName ,4)
     if Answer = vbYes then
      MsgBox ("Configuring Card : " & nicName)
      For Each nic In nics
            if nic.MACAddress = Card.MacAddress then
              msgbox ("found card " & card.macaddress & "     "   &  nic.macaddress)
              nic.SetDNSServerSearchOrder(arrDNSServerSearchOrder)
            nic.SetDNSDomain("Put_your_domain.local")      
            nic.SetWINSServer strPrimaryServer, strSecondaryServer
            nic.SetTCPIPNetBIOS(ENABLED)
            Set nicClass = objWMIService.Get(nic.Path_.class)
              nicClass.SetDNSSuffixSearchOrder(arrDNSDomainSuffixSearchOrder)
           end if
        Next
     end if
Next

sorry,  there was a typo for the WINS settings.


corrected:

--------------------------------





strComputer = "."
 
Const DEFAULT = 0
Const ENABLED = 1
Const DISABLED = 2


arrDNSServerSearchOrder = Array("192.18.4.1", "192.18.18.8", "144.16.21.1", "144.12.12.1")
arrDNSDomainSuffixSearchOrder = Array("cre.dir.se.com", "s.dir.se.com", "w.dir.sa.com", "c.ta.com.se", "in.ea.com.au", "ext.d.do.com", "tea.com.sa", "corl.tea.c.sa", "t.com.sa")
strWINSPrimaryServer = "192.18.61.1"
strWINSSecondaryServer = "192.18.10.5"


Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

Set nics2 = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter Where NetEnabled=True")


For Each Card in nics2
     nicName = Card.NetConnectionID
     Answer = MsgBox("Set this NIC card?" & nicName ,4)
     if Answer = vbYes then
      MsgBox ("Configuring Card : " & nicName)
      For Each nic In nics
            if nic.MACAddress = Card.MacAddress then
              msgbox ("found card " & card.macaddress & "     "   &  nic.macaddress)
              nic.SetDNSServerSearchOrder(arrDNSServerSearchOrder)
            nic.SetDNSDomain("Put_your_domain.local")      
            nic.SetWINSServer strWINSPrimaryServer, strWINSSecondaryServer
            nic.SetTCPIPNetBIOS(ENABLED)
            Set nicClass = objWMIService.Get(nic.Path_.class)
              nicClass.SetDNSSuffixSearchOrder(arrDNSDomainSuffixSearchOrder)
           end if
        Next
     end if
Next


 




Superb chakko..this is what im looking for.

but i didnt add entries to nic card in windows 7. and also its getting error while trying to run the script in windows server 2003. attaching error screenshot
also can u remove mac address display and domain as we are not doing this task.
our task is to add only dns and wins entries and suffixes.
DC team will add domain. We are not doing the task.

error.JPG
Ignore my previous comment..

Chakko it is working fine on my home pc..

Can u do one thing??Please remove displaying mac address and register dns suffix for this connection..other than that everything is perfect. Also im getting error while trying to execute the script in windows server 2003..I have attached screenshot in the previous comment.

Actually im using this script for windows server 2003 and 2008.

Please help me...
ASKER CERTIFIED SOLUTION
Avatar of chakko
chakko
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Chakko..

The script is working fine.

Excellent Chakko..You make a star.

God Bless You.
Excellent Script
Chakko I have raised another incident ID: 27343088(Need to configure RDP timeout value using VBScript for win 2003 and win 2008 servers.)

Attaching source code here and pls make a script for win 2003 and win 2008 as mentioned in the screenshot.

Please create it if possible.
'TERMINAL SERVICES CONNECTION SETTINGS LOGON TAB
'*************************************************
Set colItems = objWMIService.ExecQuery("Select * from Win32_TSSessionSetting")
 
For Each objItem in colItems
    objItem.TimeLimitPolicy = 0 'ENABLES Connection Override for Time Settings
    objItem.Put_ 'Commits the override so other settings will go through without error
    errResult = objItem.TimeLimit("DisconnectedSessionLimit", 60000) 'Disconnected for 1 Min
    errResult = objItem.TimeLimit("ActiveSessionLimit", 3600000) 'Active for 1 Hour
    errResult = objItem.TimeLimit("IdleSessionLimit", 600000) 'Idle for 10 mins
    objItem.BrokenConnectionPolicy = 0 'ENABLES Connection Override for Broken Connections
    errResult = objItem.BrokenConnection(1) 'ENDS Broken Connections
    objItem.ReconnectionPolicy = 0 'ENABLES Connectin Override for Reconnecting Sessions
    objItem.Put_
Next

Open in new window

windows-server-2003.jpg
windows-server-2008.jpg