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!
10 comments:
Brilliant script, will save loads of time !
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.
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 ?
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.
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!
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.
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.
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
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
Once I initially commented I clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the identical comment. Is there any manner you can take away me from that service? Thanks! casino slots
Post a Comment