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
845 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

737 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