Wednesday, June 18, 2008

Change DNS/WINS IP on Multiple Servers

I was recently asked if I could change the DNS & WINS IP address on multiple servers via script. PowerShell to the rescue! After a brief search, I found a great post. Following is my implementation.

function Set-DNSWINS {
#Get NICS via WMI
$NICs = Get-WmiObject '
-Class Win32_NetworkAdapterConfiguration '
-ComputerName $_ '
-Filter "IPEnabled=TRUE"

foreach($NIC in $NICs) {
$DNSServers = "12.34.5.67","76.54.3.21"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration("TRUE")
$NIC.SetWINSServer("12.345.67.890", "12.345.67.891")
}
}

function Get-FileName {
$computer = Read-Host "Filename of computer names?"
return $computer
}

$f = Get-FileName
Get-Content $f foreach {Set-DNSWINS}

Gotta love PowerShell!

12 comments:

Virtu-Al said...

Brilliant script, will save loads of time !

cheap wow gold said...

If you are cheap wow gold trying any unknown cheats to earn gold, you would cheapest wow gold face some problem and your account will be black out. So don't try to wow gold cheap find cheats instead try to wow7gold follow the guideline of world of warcraft. These tips could euwowgoldwork as gold cheat and can help a lot to earn gold and money. World of Warcraft is the most exiting online game and while Playing the game most of the players struggle ogpal to earn a lot of gold.

Most of the players World Of Warcraft Goldtry search cheat code for this game to earn gold. This article will help xowow you a lot to earn more and more gold.The best way to earn gold in this online game is by going through the guidelines wow gold for saleand other information about wowgold4europethe game that are available on the internet .

cheap wow gold said...

WoW shares many wow gold of its features with previously launched games. Essentially, you battle with wow gold cheap monsters and traverse the countryside, by yourself or as a buy cheap wow gold team, find challenging tasks, and go on to higher aoc gold levels as you gain skill and experience. In the course of your journey, you will be gaining new powers that are increased as your skill rating goes up. All the same, in terms of its features and quality, that is a ture stroy for this.WoW is far ahead of all other games of the genre the Wow Gold game undoubtedly is in a league of its own and cheapest wow gold playing it is another experience altogether.

Even though WoW is a Cheap Wow Gold rather complicated game, the controls and interface are done in warhammer gold such a way that you don't feel the complexity. A good feature of the game is that it buy gold wow does not put off people with lengthy manuals. The instructions WOW GOLD cannot be simpler and the pop up tips can help you start playing the game World Of Warcraft Gold immediately. If on the other hand, you need a detailed manual, the instructions are there for you to access. Buy wow gold in this site,good for you, BUY WOW GOLD.

AlbertWT said...

Hi,

I wonder if there is a script which change the current static DNS setting in All my Windows XP into Dynamic ?

so far I was able to use the following script:


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
If errEnable = 0 Then
Wscript.Echo "DHCP has been enabled."
Else
Wscript.Echo "DHCP could not be enabled."
End If
Next


which convert the Static IP into DHCP from VBScript.

Any idea please ?

Darrin Henshaw said...

I know this is an old post, but someone took this script and ran into an issue. Posted it on powershellcommunity.org. The line:

Get-Content $f foreach {Set-DNSWINS}

I think it should be:

Get-Content $f | foreach {Set-DNSWINS}

Missing the pipe character between Get-Content and foreach.

Eric said...

everytime I run this, I get the following error:

Missing expression after unary operator '-'.
At C:\Test\wins-dns.ps1:6 char:2
+ - <<<< ComputerName $_ '

Can anyone tell me why? I am running it exactly as posted and with the change suggested from the previous poster.

Thanks!

Wes Stahler said...

Eric - the editor I was using at the time was not very friendly. Check to make sure that the line continuation characters are "`" instead of "'". Once I replaced those 3 instances, it worked fine.

Anonymous said...

Rip Blu-ray for Mac with Blu-ray Ripper for Mac, snow Leopard included.- Free Download and have a try.
Ultimate Blu-ray video converter is actually an 3-in-one software including Blu-ray Ripper, DVD Ripper and Video Converter.
Blu-ray ripper enables you directly rip and convert your Blu-ray movies and general DVDs, even the protected DVDs and Blu-ray DVDs into other popular audio and video formats.

Steve Blair said...

Hi, I am getting the following error when I run the script on a Windows Server 2008 R2 machine.
It also comes with a prompt
C:\Temp\PC.txt
C:\Temp\PC.txt:
Get-Content : Cannot bind argument to parameter 'Path' because it is an empty string.
At C:\Temp\DNS_Master_File.ps1:18 char:12
+ Get-Content <<<< $f | foreach {Set-DNSWINS}
+ CategoryInfo : InvalidData: (:) [Get-Content], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.GetC
ontentCommand

Steve Blair said...

Hi, I forgot to say I have taken out the line $NIC.SetWINSServer(“12.345.67.890″, “12.345.67.891″)

as we dont use WINS servers.
Thanks

レディースバッグ said...

レディースファッション
水着
ワンピース
チュニック
レディースバッグ
水着通販
水着販売
アウター
ジャケット
ブレザー
パーカー
コート
スプリングコート
トレンチコート
ダウンジャケット
レザージャケット
ブルゾン
ジャンパー
ルームウェア
マジコン
R4 Card
R4
R4i
R4 SDHC
R4i SDHC
R4 cards
R4i ds
R4 ds card
R4i 3ds
R4i gold
Acekard 2i
R4 DS
ds r4
R4DS
Thanks for your great post.I like this very much, please write more about these, wait for your update.

حسام داود said...

شركة تسليك مجاري بالرياض
شركة تسليك مجارى بالرياض
level تسليك المجاري بالرياض
افضل شركة تنظيف بالرياض
تنظيف شقق بالرياض
شركة تنظيف منازل بالرياض
شركة غسيل خزنات بالرياض
افضل شركة مكافحة حشرات بالرياض
رش مبيدات بالرياض
شركة تخزين عفش بالرياض
شركة تنظيف مجالس بالرياض
تنظيف فلل بالرياض
ابى شركة تنظيف بالرياض