Adding WINS ip to server NIC configuration

SquigglyMonkey
SquigglyMonkey used Ask the Experts™
on
I'm needing to add a WINS server entry to a bunch of servers(please don't ask why).
I modified a DNS script I used recently and although it runs, it does not actually add the WINS entry.
$computer = get-content .\systems.txt
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
  Foreach($NIC in $NICs) {
#$WINSServers = “1.2.2.2",”1.2.2.3"
$NIC.SETWINSSERVER (“1.2.2.2",”1.2.2.3")
}

Open in new window


I tried it with and without $winsservers, same result, the IP is not added to wins entry on the server.

I actually only need one entry, not 2, but when it failed initially, I added the second entry to rule out that being the issue somehow.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2014

Commented:
I see some odd quotes in the above code, so let's make sure those aren't the issue.  There also shouldn't be a space before the parentheses.
$WINSServers = "1.2.2.2"
$NIC.SetWINSServer($WINSServers)

Open in new window

Let's see if it works with that syntax.

Author

Commented:
Sadly no, I did that earlier also, when I was writing this post I used the old "fake IP's" which had the odd double quotes.

How can I find all of the set commands that are available like setwinsserver? Maybe I am using the wrong one?
Top Expert 2014

Commented:
To see all properties and methods you just pipe the object to Get-Member, but no, there's no other method that applies to WINS settings.

It looks like you have to supply both primary and secondary WINS servers.  If you don't have a secondary, then just an empty string will do.
$WINSServers = "1.2.2.2",""

Open in new window

I just confirmed this to work on a test machine.

When you run the SetWINSServer method, you will get a code back.  If the resultcode is anything other than 0 it is an error.  This page shows what the different errors are - https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/setwinsserver-method-in-class-win32-networkadapterconfiguration
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Author

Commented:
I don't get it... Getting error 68
This is the exact script, just the ip is changed.
$computer = get-content .\systems.txt
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq "TRUE”}
  Foreach($NIC in $NICs) {
$WINSServers = "1.1.1.1",""
$NIC.SETWINSSERVER($winsservers)
}

Open in new window

Top Expert 2014
Commented:
Ah, I tested with a slight variation than what I posted.  Should have known better...
Change your lines 4 and 5 like below.
$WINSServers = "1.1.1.1"
$NIC.SETWINSSERVER($winsservers,"")

Open in new window


You could also do something like
$PrimaryWINS = "1.1.1.1"
$SecondaryWINS = "1.1.1.2"
$NIC.SETWINSSERVER($PrimaryWINS,$SecondaryWINS)

Open in new window

It's basically about the difference between a string array vs. two separate strings.

Author

Commented:
Thanks Foo, that did it. Moving that ,""  came up with error 0.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial