Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Netbios over TCPIP - Scripted

Status
Not open for further replies.

ste52653

IS-IT--Management
Apr 10, 2007
36
CA
I need to add 2 WINS server IP's and enable netbios over tcpip on 140 servers.

I have a way to do the 2 WINS IP's via psexec and NetSH but I have no idea how to enable netbios via script. Also another thing is that I do not want netbios enabled on all adapters, only the "Public Team" adapter (we have 2 private adapters that we do not want netbios enabled on).

Thanks very much!
-Steve
 
You can use a vbscript. Use the code below and save it to a .vbs file, you can then call the vbscript from a command prompt when you are using the netsh or psexec for the other part. Hope this helps.

-jhaith



Option Explicit
On Error Resume Next

Dim objWMIService
Dim objNetAdapter
Dim strComputer ' Can specify IP address or hostname or FQDN
Dim colNetAdapters
Dim errEnableNetbios

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

'Set the where clause to select the adapter you want. See for options.
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where ")

For Each objNetAdapter in colNetAdapters
errEnableNetbios = objNetAdapter.SetTcpipNetbios(1)
Next

'Display result or error code

If errEnableNetbios=0 Then
Wscript.Echo "NetBIOS has been successfully disabled on the adapters"
Else
Wscript.Echo "Disabling NetBIOS was not successful. Error code " & errDisableNetbios
End If
 
This does help, thanks.. I never thought of this until you posted... If I use psexec and netsh to add the WINS Primary and secondary IP's to the Public Team adapter, I can then use this script you provided above to set the netbios option by using the where WINSPrimaryServer = primaryIP, however I'm not sure the exact syntax to use for the "where" clause... can you help with that too?

Thanks again so much!

-Steve
 
For strComputer, specify the IP Address for that particular interface. Here's an example.

strComputer = "192.168.0.1"

Set colNetAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPAddress = " & strComputer)

-jhaith
 
Ya ok that will work too; however that only works for one computer, but I need to enable this on about 140 servers. I would have a servers.txt file with a list of servers. I assume that would still work for the WHERE clause that you stated above right?

Set colNetAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPAddress = " & strComputer")

I just have to figure out the part to tell it to loop through the txt file instead of a single computer name or IP address right?

Thanks again.
-Steve
 
Steve,

Just got your reply, I'll write you a script this afternoon that will do all of that, check back later in the day =)

-jhaith
 
Awesome thanks very much I appreciate it. I've been trying to get it to work but it just loops through the servers.txt list, never stops. :( Wish I knew more about scripting.

Thanks again!!

-Steve
 
Steve,

Try this script. You'll need to create a csv with all the IP Addresses and change the command at the bottom to the psexec/netsh command you are using for the WINS. Let me know if you have any problems.

-jhaith

Option Explicit
On Error Resume Next

Dim objWMIService
Dim objNetAdapter
Dim objFSO
Dim objFile
Dim wshShell
Dim colNetAdapters
Dim strFile
Dim strText
Dim strComputer
Dim errEnableNetbios
Dim arrList
Dim i


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Admin\Scripts\List.txt", 1)

Do Until objFile.AtEndOfStream
strText = objFile.ReadAll
arrList = split(strText, ",")

For i = 0 To ubound(arrList)
strComputer = arrList(i)

Wscript.Echo "IP Address: " & strComputer

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPAddress = " & strComputer)

For Each objNetAdapter in colNetAdapters
errEnableNetbios = objNetAdapter.SetTcpipNetbios(1)
Next

If errEnableNetbios=0 Then
Wscript.Echo "NetBIOS has been enabled."
Else
Wscript.Echo "ERROR! NetBIOS was not enabled. Error code " & errDisableNetbios
End If

Set wshShell = WScript.CreateObject("WScript.shell")
wshShell.Run " " & strComputer 'psexec/netsh command to run
wshShell.Sleep(1000)
Next

Loop

Set objFSO = Nothing
Set objFile = Nothing
Set objWMIService = Nothing
Set colNetAdapters = Nothing
Set wshShell = Nothing


 
WOW! Thanks very much it looks great! I have one question though (sorry). You mention a CSV file, but in the script objFile = objFSO.OpenTextFile. Do I really create a CSV for this or will a plain text file of IP addresses do, like this:

192.168.1.2
192.168.1.3
192.168.1.4
192.168.1.5

Thanks again so very much for your help on this, it's amazing thank you.

-Steve
 
OK sorry I see now that you specified in the script split(strText, ",") I have created the servers.txt file as follows:

192.168.1.2,192.268.1.3,192.168.1.4

The script runs, looks like it goes ok, but for whatever reason doesn't appear to make the netbios option enabled. I ran it against my local pc to test and made sure the adapter had a static address (192.168.1.122) and it ran fine, here's the output:

C:\scripts>cscript netbios-enabledv2.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

IP Address: 192.168.1.122
NetBIOS has been enabled.

Yet when I check my adapter/WINS tab, NetBIOS is disabled still... Any ideas what I'm doing wrong?

thanks again,
-Steve
 
no, i switched the one I was testing on (local laptop) to static IP.

All servers that this will be run on eventually are all static IP (no dhcp).

-Steve
 
Steve,

Yeah it's hard to tell without being there what could be wrong, could be permissions/settings/etc, WMI is a little tricky and there's alot of exceptions to querying it. Probably need to experiment with the script to make sure it's pulling back the data correct. Also you may want to check out the MSDN reference, it may have something you're looking for. Hope it helps and good luck.


-jhaith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top