Solved

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

Posted on 2011-09-27
13
835 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:jashir101
  • 8
  • 5
13 Comments
 

Author Comment

by:jashir101
ID: 36713959
Guys,

Can anyone provide a soultion for this??
0
 
LVL 22

Expert Comment

by:chakko
ID: 36714170
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?
0
 

Author Comment

by:jashir101
ID: 36714298
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....
0
 
LVL 22

Expert Comment

by:chakko
ID: 36714687
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
0
 

Author Comment

by:jashir101
ID: 36714930
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?"
0
 
LVL 22

Expert Comment

by:chakko
ID: 36812958


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

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 22

Expert Comment

by:chakko
ID: 36812961
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


 




0
 

Author Comment

by:jashir101
ID: 36814152
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
0
 

Author Comment

by:jashir101
ID: 36818799
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...
0
 
LVL 22

Accepted Solution

by:
chakko earned 500 total points
ID: 36826037
try this.  I was able to test on Win 2003 but not 2008 at this time.

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 objWMIService2 = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set nics = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")

Set nics2 = objWMIService2.ExecQuery("Select * from Win32_NetworkAdapter")


For Each adaptr in nics2
     nicName = adaptr.NetConnectionID
     if Left(NicName ,1)<> "" Then
       Answer = MsgBox("Set this NIC adaptr?" & nicName ,4)
       if Answer = vbYes then
        MsgBox ("Configuring adaptr : " & nicName)
        For Each nic In nics
            if nic.MACAddress = adaptr.MacAddress then
              nic.SetDNSServerSearchOrder(arrDNSServerSearchOrder)      
              nic.SetWINSServer strWINSPrimaryServer, strWINSSecondaryServer
              nic.SetTCPIPNetBIOS(ENABLED)
              Set nicClass = objWMIService.Get(nic.Path_.class)
              nicClass.SetDNSSuffixSearchOrder(arrDNSDomainSuffixSearchOrder)
           end if
        Next
       end if
     end if
Next

0
 

Author Comment

by:jashir101
ID: 36890127
Thanks Chakko..

The script is working fine.

Excellent Chakko..You make a star.

God Bless You.
0
 

Author Closing Comment

by:jashir101
ID: 36890133
Excellent Script
0
 

Author Comment

by:jashir101
ID: 36890187
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I had a question today where the user wanted to know how to delete an SSL Certificate, so I thought that I would quickly add this How to! Article for your reference. WHY WOULD YOU WANT TO DELETE A CERTIFICATE? 1. If an incorrect certificate was …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now