Change DNS using Powershell

Posted on 2010-11-16
Last Modified: 2012-05-10
Hi there.

I've managed to find the attached powershell script that allows me to change dns setting on a server.

If works fine except that i can only add two addresses.

I'm looking to add more than that within the advanced setting on the nic.  how do i go about this?
#Get NICS via WMI
$Nics = get-WMIObject -class Win32_NetworkAdapterConfiguration -ComputerName $_ -Filter "IPEnabled=TRUE"

foreach ($NIC in $NICs){

function Get-filename{
$computer = "e:\Txt_Files\dns.txt"
return $Computer

$f = Get-Filename
get-content $f | foreach {set-DNSWINS}

Open in new window

Question by:Colchester_Institute
  • 2
  • 2
LVL 70

Accepted Solution

Chris Dent earned 500 total points
ID: 34144600

Hmm why do you think you can only set two?

This should work:
$DNSServers = "", "", ""

Open in new window

There's no reason to limit the number there to two.


Author Comment

ID: 34144667
ahh yes that works...

it was my own fault also where i'd played around with the syntax

it doesnt however let me put more than two wins addresses there a way out of curiosity i can do that?
LVL 70

Expert Comment

by:Chris Dent
ID: 34144887

Unfortunately the SetWINSServer method is a bit limited, NetSh should be able to do it, but I can't seem to get the syntax right for more than one address.

The last resort is hitting the registry, WINS addresses hide here:


There's a NameServerList beneath that. We can set that like this:
$DnsServers = "","", ""
[String[]]$WinsServers = "yyy.yyy.yyy.yyy", "yyy.yyy.yyy.yyy", "yyy.yyy.yyy.yyy"

Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled=$True" | ForEach-Object {

  Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\services\NetBT\parameters\Interfaces\Tcpip_$($_.SettingID)" `
    -Name "NameServerList" -Value $WinsServers

Open in new window

Note that we have to force $WinsServers to be a String array (String[]) or it'll tell us to get lost.

A bit more convoluted that I prefer, but it should work :)



Author Comment

ID: 34145140
why thank

my manager has said hes not fussed bout the wins but it was for my own learning curve.

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now