Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: change all WInS IPs in the enterprise with PowerShell

366 views
Skip to first unread message

Dylan

unread,
Jun 30, 2009, 5:52:01 PM6/30/09
to

Something like this VBS script? Hope it's not too late.

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery("Select * From
Win32_NetworkAdapterConfiguration Where IPEnabled = True")
strPrimaryServer = "172.16.1.240"
strSecondaryServer = "172.16.1.241"

For Each objNetCard in colNetCards
objNetCard.SetWINSServer strPrimaryServer,strSecondaryServer
Next
--
MCSA J.Dylan McNeill

"Richardg" wrote:

> Hi and thanks for advice.
>
> Yes you are right the Netsh command will do the job, the problem is that not
> all the nics have the same name (of course) So the command of
> netsh interface IP set wins name= "local area connection" source=static
> addr=xxx.xxx.xxx would do the trick the problem I am now facing is to set up
> a batch file to searh for the name and then insert that into the netsh
> command. I know that netsh interface ip show config will pull the name but to
> be honest here I am still in the learning cruve. I think I bit off more then
> I can chrew here.
>
> I have tried a lot of the PS and VB scripts on the web and for some reason
> they say they have worked but when I check the machine it has not changed. I
> am using my admin ID and I know it works, I have tried from my machine and on
> the server itself but have had no luck.
> Time is running out so if someone could provide me with some help it would
> be Greatly Appreciated.. Thanks
> --
> Thanks very much.
> Regards,
>
>
>
> "Vadims Podans [MVP]" wrote:
>
> > have you tryed 'netsh.exe' utility?
> > --
> > WBR, Vadims Podans
> > MVP: PowerShell
> > PowerShell blog - www.sysadmins.lv
> >
> > "Richardg" <Rich...@discussions.microsoft.com> rakstīja ziņojumā
> > "news:96982933-F26F-4E0C...@microsoft.com"...
> > > Wondering if anyone has a script that can change the Wins IP address on a
> > > server.
> > >
> > > I am trying to figure it out and of course was given the task this morning
> > > and it is needed for this Sat night.
> > >
> > > Any help would be greatly appreciated.
> > >
> > > --
> > > Thanks very much.
> > > Regards,
> > >
> > > Richard G
> >
> >

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Mike Pfeiffer

unread,
Jun 30, 2009, 10:49:26 PM6/30/09
to
> > > "Richardg" <Richa...@discussions.microsoft.com> rakstīja ziņojumā

> > > "news:96982933-F26F-4E0C...@microsoft.com"...
> > > > Wondering if anyone has a script that can change the Wins IP address on a
> > > > server.
>
> > > > I am trying to figure it out and of course was given the task this morning
> > > > and it is needed for this Sat night.
>
> > > > Any help would be greatly appreciated.
>
> > > > --
> > > > Thanks very much.
> > > > Regards,
>
> > > > Richard G

The equivalent to that would basically be:

Get-WmiObject -ComputerName "." `
Win32_NetworkAdapterConfiguration | ?{$_.IPEnabled -eq $True} | `
% {$_.SetWINSServer("172.16.1.240", "172.16.1.241")}

I'm guessing you'll want to do this on multiple servers. One way you
can do it is read a list of servers from a file into a variable and
then run the command on each server:

$servers = get-content c:\servers.txt
foreach ($server in $servers) {
Get-WmiObject -ComputerName $server `
Win32_NetworkAdapterConfiguration | ?{$_.IPEnabled -eq $True} | `
% {$_.SetWINSServer("172.16.1.240", "172.16.1.241")} }

Shay Levy [MVP]

unread,
Jul 1, 2009, 3:45:43 AM7/1/09
to

Hi dylan,

See this post:

http://olddogsblog.spaces.live.com/Blog/cns!C2DB05EEFA6C21A1!233.entry


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar

d> Something like this VBS script? Hope it's not too late.
d>
d> strComputer = "."
d> Set objWMIService = GetObject("winmgmts:\\" & strComputer &
d> "\root\cimv2")
d> Set colNetCards = objWMIService.ExecQuery("Select * From
d> Win32_NetworkAdapterConfiguration Where IPEnabled = True")
d> strPrimaryServer = "172.16.1.240"
d> strSecondaryServer = "172.16.1.241"
d> For Each objNetCard in colNetCards
d> objNetCard.SetWINSServer strPrimaryServer,strSecondaryServer
d> Next
d> "Richardg" wrote:
d>

>>> "Richardg" <Rich...@discussions.microsoft.com> rakst?ja zi?ojum?

Shay Levy [MVP]

unread,
Jul 10, 2009, 7:47:40 PM7/10/09
to
A one-liner using -filter instead of a where-object :)


Get-WmiObject Win32_NetworkAdapterConfiguration -filter "IPEnabled='True'"
-ComputerName (get-content c:\servers.txt) | foreach {$_.SetWINSServer("172.16.1.240",
"172.16.1.241")}


---
Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Toolbar: http://tinyurl.com/PSToolbar

MP> On Jun 30, 7:10 pm, Mike Pfeiffer <mike.pfeif...@live.com> wrote:
MP>

>> On Jun 30, 2:52 pm, Dylan <dylanmcne...@msn.com> wrote:
>>

>>> Something like this VBS script? Hope it's not too late.
>>>

>>> strComputer = "."


>>> Set objWMIService = GetObject("winmgmts:\\" & strComputer &

>>> "\root\cimv2")


>>> Set colNetCards = objWMIService.ExecQuery("Select * From

>>> Win32_NetworkAdapterConfiguration Where IPEnabled = True")

>>> strPrimaryServer = "172.16.1.240"
>>> strSecondaryServer = "172.16.1.241"

>>> For Each objNetCard in colNetCards

>>> objNetCard.SetWINSServer strPrimaryServer,strSecondaryServer
>>> Next
>>> --
>>> MCSA J.Dylan McNeill
>>> "Richardg" wrote:
>>>

>>>>> "Richardg" <Richa...@discussions.microsoft.com> rakst?ja zi?ojum?


>>>>> "news:96982933-F26F-4E0C...@microsoft.com"...
>>>>>
>>>>>> Wondering if anyone has a script that can change the Wins IP
>>>>>> address on a server.
>>>>>>
>>>>>> I am trying to figure it out and of course was given the task
>>>>>> this morning and it is needed for this Sat night.
>>>>>>
>>>>>> Any help would be greatly appreciated.
>>>>>>
>>>>>> --
>>>>>> Thanks very much.
>>>>>> Regards,
>>>>>> Richard G
>>>>>>

>> The equivalent to that would basically be:
>>
>> Get-WmiObject -ComputerName "." Win32_NetworkAdapterConfiguration | ?
>> {$_.IPEnabled -eq $True} | % {$_.SetWINSServer("172.16.1.240",
>> "172.16.1.241")}
>>
>> I'm guessing you'll want to do this on multiple servers. One way you
>> can do it is read a list of servers from a file into a variable and
>> then run the command on each server:
>>
>> $servers = get-content c:\servers.txt
>> foreach ($server in $servers) {
>> Get-WmiObject -ComputerName $server
>> Win32_NetworkAdapterConfiguration | ?{$_.IPEnabled -eq $True} | %
>> {$_.SetWINSServer("172.16.1.240", "172.16.1.241")}
>> }
>>

MP> That was supposed to be a one liner... Here it is with line
MP> continuation, hopefully easier to read:
MP>
MP> $servers = get-content c:\servers.txt
MP> foreach ($server in $servers)
MP> {
MP> Get-WmiObject -ComputerName $server `
MP> Win32_NetworkAdapterConfiguration | ?{$_.IPEnabled -eq $True} | `
MP> % {$_.SetWINSServer("172.16.1.240", "172.16.1.241")}
MP> }


0 new messages