Script to Change DNS Servers on Remote Server

I am new to powershell and I am trying to construct a script to change the DNS servers settings on a whole list of machines remotely. I have the list of machines that I want to change in a txt file. I have read several posts on this and tried several different
methods but I cannot seem to get it to work. Here is my code, any help is much appreciated.
$servers = Get-Content C:\PathToFile\computers.txt
foreach($server in $servers)
    Write-Host "Connect to $server..."
    $nics = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $server -ErrorAction Inquire | Where{$_.IPEnabled -eq "TRUE"}
    $newDNS = "10.1.1.1","10.2.2.2"
    foreach($nic in $nics)
        Write-Host "`tExisting DNS Servers " $nic.DNSServerSearchOrder
        $x = $nic.SetDNSServerSearchOrder($newDNS)
        if($x.ReturnValue -eq 0)
            Write-Host "`tSuccessfully Changed DNS Servers on " $server
        else
            Write-Host "`tFailed to Change DNS Servers on " $server

http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/28/use-powershell-to-configure-static-ip-and-dns-settings.aspx
Ed Wilsons Blog.
$computer = Get-Content C:\PathToFile\computers.txt
$wmi = Get-WmiObject win32_networkadapterconfiguration  -computername "$computer" -filter "ipenabled = 'true'"
$wmi.SetDNSServerSearchOrder("10.0.0.15", "255.255.255.0")
I dont have the feasibility to check as of now. Please test and let me know.
Thanks
Azam
Mark As an Answer if it answered your question or helpful if helped.

Similar Messages

  • Script to change DNS

    Guys,
    We are changing the IP address of one our domain contoller which is also a DNS server. Need a script to change the dns server ip in about 70 servers, script should to change only the old ip address while the other 2 DNS addresses should remain as it
    is.

    You can try
    http://superuser.com/questions/463096/change-dns-with-script
    http://blogs.technet.com/b/heyscriptingguy/archive/2014/01/26/weekend-scripter-modify-dns-settings-via-windows-powershell.aspx
    http://social.technet.microsoft.com/Forums/windowsserver/en-US/ed3f4c9e-1467-4795-b9d1-ae41937b8962/script-to-change-dns-servers-on-remote-server?forum=winserverpowershell
    -Greg

  • Pros and cons of changing DNS servers?

    Hello guys, First of all I am a non technical person related to DNS servers. So I want to know what are the pros and cons if you change your DNS servers?
    I wanted to access Netflix but its not yet available in my country so I came across http://unotelly.com/ . They provide a method to access but by changing DNS. Can someone guide should I do it? What are the pros and cons? Thank you

    The DNS is what translates in and outgoing URLs to your local domain server. Changing it may have no adverse effect. It could result in faster or slower translations, but you may not even notice either. However, if it does not work properly, then you will not get web sites in your browser until you revert back to a DNS that you know works or delete all added DNS entries which returns to the system default.

  • Edit catt script for changes in in web appl server higher than 6.4 release

    Hello Guru’s,
    Will you help me in editing the CATT script for changes in Web application server release higher than 6.4 release, when I look for edit mode it was showing the following message. will anyone suggest me is there any way to make changes.
    “While I was choosing change mode it was displaying the above message ( Message No:TT005)”
    Full points for the answer

    It seems there there is no problem with my FireFox 7.0.1 on my Mac OSX 10.7.2. So, maybe you can solve the problem by updating your OS. The only minor problem here is that Firefox doesn't display in the Tibetan fonts that you choose, it always display in Kailas font for Tibetan.

  • Changing dns servers vs cname

    I'm confused...I'm using iweb 2.0.3, I've published my pages to .mac, and now I want to have my website name (www.stoneaxefarm.com) which I purchased through Register.com point to those pages on .mac rather than to the servers someplace in Tennessee where my site is currently residing.
    Register.com wants me to enter the new dns servers...there's nothing about cnames.
    the current dns looks like : ns57.1and1.com do I replace that with www.mac.com/myusername/etc?
    then how do I get my mail that currently is forwarded from [email protected] to [email protected]?
    Thanks, Martha H.

    Register.com wants me to enter the new dns servers...there's nothing about cnames.
    It's in the Help
    [How do I change mu Domain alias|http://help.register.com/cgi-bin/registerhelp.cfg/php/enduser/std_adp.php?p_faqid=1270&p_created=1097608669&p_sid=maCHzq5 j&p_accessibility=0&p_lva=1252&p_sp=cF9zcmNoPTEmcF9zb3J0X2J5PSZwX2dyaWRzb3J0PSZw X3Jvd19jbnQ9NCZwX3Byb2RzPTAmcF9jYXRzPTAmcF9wdj0mcF9jdj0mcF9wYWdlPTEmcF9zZWFyY2hf dGV4dD1jbmFtZQ**&p_li=&ptopview=1]

  • Automating the process of changing SAP servers when one server is down

    Hi,
    We have observed that sometimes users are unable to run a CRM IC web application due to server being down.
    So we want to automate the process that if a server is down then it will change to another server so that the application can run and the downtime is reduced.
    Can you please let me know if anyone has done anything on this front.
    Kindly send your suggestions.
    Thanks in advance.
    Regards,
    Jaisish Mohanty

    You can use sapwebdispatcher together with logon groups for this purpose:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/be/6041418e998739e10000000a1550b0/frameset.htm
    Markus

  • [Locked] Switching from testing server to remote server

    I set up php pages on a testing server successfully. I exported the database from the testing server to the remote server no problem.  But I don't understand how to switch the pages from the testing server to my remote server and make the connection to the database there. I read the manual about switching the connections, but I'm not having any luck. Here's what's not clear:
    Am I supposed to move the page to my local root folder before putting it to the remote server?  When I do this, the Databases tab says there is no connection, though the page still starts with this code: <?php require_once('file:///C|/XAMPP/htdocs/TRS/Connections/trs_db.php'); ?>  When I try to make a new connection, I get an error message that references that code.
    Do I also move the server scripts and connections folders from the remote server to the local root folder then put them to the server?
    The testing server tutorial stops short of explaining this switch, and the manual doesn't seem to address the testing server at all.
    Thanks.

    Sorry! My question is the following: Has anyone switched from saving calendar events to their e-mail server to icloud with success? I do not want to make the switch if I will lose events or events will not appear as they do now, or if I will lose everything in the notes that I write for events.

  • Manually set DNS servers in BT Homehub 2.0 with BT...

    Rather than having to se my DNS manually in network connections I was wondering if there was a setting on the homehub for changing DNS servers as I would like to use OpenDNS so I can test their web filtering capabilities.
    I have browsed the hub settings but there doesn't appear to be any setting to set DNS servers statically, it seems automatically use BTs DNS servers when the connection is live.

    Hi hippomango, your solution to override the DNS settings in the BT Homehub sounds interesting - except that I cannot get them to work!?
    I have a BT Homehub 3.0 (yes, you still can't override the default DNS settings), but I can't see that making much of a difference. I can't get any of the computers (wired or wireless) to use the OpenDNS settings in the 2nd router, they always find the BT DNS.
    Wondering if you can explain some more detail about your set up if possible?
    - Presumably your BT Hub is still your default gateway?
    - Your 2nd router (Netgear) has the BT Hub as the default gateway?
    - All computers are DHCP? Or do you have some static? (At least 1 of my machines needs a static local IP, but DHCP for the majority)
    TBH, I don't know how the DMZ helps in this case? (But that may be because I don't quite understand what's going on!) Doesn't the DMZ influence incoming traffic? Don't we want to direct outbound traffic?
    Thanks for any info.

  • Unable to create a clustered VM using Remote Server Administration Tools - Failover Cluster Manager

    Hi
    I am using two Hyper-V Server 2012 R2 and a single WS2012 Datacenter Edition with GUI Interface for management purpose.
    I have installed Failover Clustering feature on these two Hyper-V servers and remote server administration tools for Failover Clustering on WS2012 DC Edition with GUI.
    I have created cluster using powershell cmdlets on Hyper-V server because I was unable to create a cluster using RSAT-Failover Clustering (May be some privileges issues).
    The problem is " I am still not able to create a Hyper-VM using Failover Cluster Manager on WS2012 DC Edition server". It gives me an error "Invalid operation"
    Any Help regarding this issue will be very appreciated.
    Thanks in Advance.....
    Abhinav | MCTS-Server Virtualization

    Thanks Tim for your response but atleast I should be able to create and configure VMs for high availability. 
    I think this is not the issue which I am facing. It gives me an error "invalid class". There is something missing.
    Please check and let me know if it can be solved. Any help will be really appreciated.
    Thanks in advance.
    Abhinav | MCTS-Server Virtualization

  • Optimize Powershell script (reboot remote Server and Check Services)

    Hi there,
    For my next maintenance Weekend i try to write a script to reboot all Servers and check after the reboot all automatic Service if there are running or not.
    Now the Script works fine for me so far, but it is not perfect. I would like to ask if anybody could help me to optimize it.
    # First Part: Reboot Servers
    $date = Get-Date -Format dd-MM-yyyy
    # Get list of Servers
    $Servers = Get-Content "D:\Scripts\Reboot\servers.txt"
    # Reboot each server
    ForEach ($Server in $Servers)
    "Computer $Server initiated reboot at $(Get-Date)" | Add-Content -Path D:\Logs\Reboot\Rebootlogs_$date.txt
    Restart-Computer $Server -Force -Wait
    # Check each Server
    forEach ($Server in $Servers)
    if (Test-Connection $Server -quiet) { "Computer $Server verified to be responding to ping at $(Get-Date)" | Add-Content -Path D:\Logs\Reboot\Rebootlogs_$date.txt }
    else { "Computer $Server unresponsive to ping at $(Get-Date)" | Add-Content -Path D:\Logs\Reboot\Rebootlogs_$date.txt }
    # Seconde Part: Check Services
    # Get list of Servers
    $Servers = Get-Content "D:\Scripts\Reboot\servers.txt"
    # Check Auto Services on each Server
    ForEach ($Server in $Servers)
    ForEach-Object {
    Write-Output $Server | Out-File -FilePath "D:\Logs\Reboot\services_$date.txt" -Append
    # get Auto that not Running:
    Get-WmiObject Win32_Service |
    Where-Object { $_.StartMode -eq 'Auto' -and $_.State -ne 'Running' } |
    # process them; in this example we just show them:
    Format-Table -AutoSize @(
    'Name'
    'DisplayName'
    @{ Expression = 'State'; Width = 9 }
    @{ Expression = 'StartMode'; Width = 9 }
    'StartName'
    ) | Out-File -FilePath "D:\Logs\Reboot\services_$date.txt" -Append
    As you can see i do it in two parts, the perfect way might be in one, where i check one server and write also just one log with all information.
    At the Moment the log files Looks like that:
    Reboot:
    Computer server1 initiated reboot at 04/28/2015 15:14:51
    Computer server2 initiated reboot at 04/28/2015 15:16:40
    Computer server1 verified to be responding to ping at 04/28/2015 15:17:41
    Computer server2 verified to be responding to ping at 04/28/2015 15:17:44
    Service:
    Server1
    Name           DisplayName         State   StartMode StartName                
    RemoteRegistry Remote Registry     Stopped Auto      NT AUTHORITY\LocalService
    sppsvc         Software Protection Stopped Auto      NT AUTHORITY\NetworkSer...
    Server2
    Name           DisplayName         State   StartMode StartName                
    RemoteRegistry Remote Registry     Stopped Auto      NT AUTHORITY\LocalService
    sppsvc         Software Protection Stopped Auto      NT AUTHORITY\NetworkSer...
    Now my Question is how to Change maybe my Loop or code to get one Log like that:
    Computer server1 initiated reboot at 04/28/2015 15:14:51
    Computer server1 verified to be responding to ping at 04/28/2015 15:17:41
    Name           DisplayName         State   StartMode StartName                
    RemoteRegistry Remote Registry     Stopped Auto      NT AUTHORITY\LocalService
    sppsvc         Software Protection Stopped Auto      NT AUTHORITY\NetworkSer...
    Computer server2 initiated reboot at 04/28/2015 15:16:40
    Computer server2 verified to be responding to ping at 04/28/2015 15:17:44
    Name           DisplayName         State   StartMode StartName                
    RemoteRegistry Remote Registry     Stopped Auto      NT AUTHORITY\LocalService
    sppsvc         Software Protection Stopped Auto      NT AUTHORITY\NetworkSer...
    Thanks for helping.

    You could probably have something nice using Function and CmdletBinding so you can get something like:
    function reboot-myservers { blablabla }function check-myservices { blablabla }$Servers = Get-Content "D:\Scripts\Reboot\servers.txt" $servers | reboot-myservers | check-myservices
    Bruce Jourdain de Coutance - Consultant MVP Exchange http://blog.brucejdc.fr

  • I have updated my webpage - its updated on my remote server "using dreamweaver" and the date has changed, but when i go online to check nothing has changed.

    all is connected, dates changed in the remote server, i have cleared my history so that its not just going to its memory but actually looking for the page.
    does anyone have any ideas?

    I just tried to run your home page through the W3C validator and got this error:
    Sorry! This document cannot be checked.
      I got the following unexpected response when trying to retrieve <http://www.dsfiresecurity.com.au/>:  500 Can't connect to www.dsfiresecurity.com.au:80 (timeout)
    If you made recent changes to your domain name (DNS) configuration, you may also want to check that your domain records are correct, or ask your hosting company to do so.
    Nancy O.

  • DNS server Error, it says I have no DNS Servers

    DNS server Error, it says I have no DNS Servers

    We cannot help you with that amount of info..
    It says you have no DNS servers on what??
    I presume it is an apple router. What one?? What firmware?
    Plugged into what modem? Is the modem also a router? What mode is the airport in?
    If you changed your network around and have a cable modem. Did you power cycle it for at least 20min.. this is necessary.
    If you want us to help you full disclosure of the whole network.. impossible to answer without.

  • Fonts changed to Unix files when saved to a remote server

    Hi all, I read an archived thread regarding this, but not sure if my situation is related somehow. The issues others have had was that their font files were converted to Unix files at 0KB, when stuffed.
    My issue is I backed up fonts (PS and TT) from my Mac to a remote server (PC based). When that server is accessed by Mac users, some saw the file as a Unix file at 0KB. However, there were some (including myself) that saw the actual font file.
    That was a few months ago, we've retired that server since, but before doing so I transferred all the fonts to a new server. It's now a raid drive run off a Mac Xserve. After the transfer, I checked to see if the fonts were still okay, and they were showing full Mac file (no Unix). I didn't go into the new server for a couple of months, but when I did I noticed that all the fonts had been changed to Unix files. Some were at 8KB, others at 60KB. But no 0KB files. +Note: because the initial transfers was a success, the original files from the old server were deleted along with it. So there is no way of retrieving the original files. As well, were were running 10.4.10 with the original server and files. Switched to 10.5.x when files were transferred to the new server.+
    I've tried the tips here (using the Terminal method and the FileUtilsCM script) http://discussions.apple.com/message.jspa?messageID=6041364 but to no avail. I'd hate to think these fonts are scrap. As they were all purchased (and there's a whole load of them). Any input in saving these files would be of great help.
    Thanks in advance.

    The real font information is stored in a resource fork, not the data fork fo the file.  Depending type type of file system you copied them to, how you copied them, and what method you are using to look at them, you may not be seeing the resource fork.
    You can see more detail about files usng a Terminal command such as
    ls -leaO@ file
    If there is a resource fork, it will be displayed.
    If the file system was not a Mac OS X external file system, then you might want to look for a file with a similar name only starting with a leading period to make it invisible to the Finder
    ls -leaO@ /the/directory/with/your/fonts

  • Testing an ISA Server Rule, the recursive query to other DNS Servers test fails

    Hello,
    I am trying to configure the following infrastructure with ISA Server 2006 and two W2003 servers (called "Server1" and "Server2") . "Server1" is a domain controller, and in
    "Server2" is the ISA Server installed, which also has
    attached two network Ethernet cards, one called "Internal Ethernet Card", and the other one called
    "External Ethernet Card".
    The infrastructure would be:  "Internal Ethernet Card"---- ISA Server ----"External Ethernet Card"---"Router"----"Internet"
    "Internal Ethernet Card" manages the internal package traffic of the infrastructure, the network segment which belongs is isolated from what we could called the Outbound traffic, which is linked to a router. "Internal Ethernet Card" it`s
    a virtual network.
    "Internal Ethernet Card" feature configuration is the following:
    - IP address: 192.168.3.3
    - Subnet Mask: 255.255.255.0
    - DHCP Enabled: No
    - DNS Server: 192.168.3.1 (Must point to the DC "Server1" which has the DNS Service installed)
    - Default Gateway:  None  (because doesnt point to outside)
    - Primary WINS Server: 192.168.3.1  
    The "External Ethernet Card" provides, the outbound connection, and this card is connected to the physical router.
    It`s feature configuration is the following:
    - IP address: 192.168.1.50
    - Subnet Mask: 255.255.255.0
    - DHCP Enabled: No
    - Default Gateway: 192.168.1.1
    - DNS Servers: 192.168.3.1 (Must point to the DC "Server1" which has the DNS Service installed)
    After configuring the network cards, I create the following rule in the ISA Server to allow the traffic towards outside from the server and the clients which have joined to the domain:
    Action: Allow.  Protocol: DNS.  From:"Server2".  To : External.  Condition: All Users
    After applying the changes to update the configuration, I enter in the Dns Server of "Server1" and in the "Monitoring" tab, I run a "recursive query to other DNS Servers" but fails.
    Only works the "simple query against this DNS Server".
    I don`t know why fails, but I`m stucked on this issue, because in the "Server1" DNS Server, in the "domain forward IP address list", I have added two DNS addresses which work OK.
    I would appreciate some help to solve this issue.
    Thanks
    Regards 

    Hello Ms. Long, 
    Yes, you are right. In the Server1 is configured the DNS server, to use forwarders whose are set in the field "Selected domain`s forwarder IP address list", two DNS address numbers obtained from "Open DNS", which work well.
    There is no DNS Server linked to the External NIC.
    The Server1 belongs to a private network configured as "VMnet3", which it is set as follows:
    IP address: 192.168.3.1
    Subnet Mask: 255.255.255.0
    Default Gateway: 192.168.3.3
    DNS Server: 192.168.3.1
    I have tried to test your suggested idea:
    > set d2
    > google.com
    Server:  srv-dcfs-01.dominio.local
    Address:  192.168.3.1
    SendRequest(), len 42
        HEADER:
            opcode = QUERY, id = 2, rcode = NOERROR
            header flags:  query, want recursion
            questions = 1,  answers = 0,  authority records = 0,  additional = 0
        QUESTIONS:
            google.com.dominio.local, type = A, class = IN
    Got answer (113 bytes):
        HEADER:
            opcode = QUERY, id = 2, rcode = NXDOMAIN
            header flags:  response, auth. answer, want recursion, recursion avail.
            questions = 1,  answers = 0,  authority records = 1,  additional = 0
        QUESTIONS:
            google.com.dominio.local, type = A, class = IN
        AUTHORITY RECORDS:
        ->  dominio.local
            type = SOA, class = IN, dlen = 46
            ttl = 3600 (1 hour)
            primary name server = srv-dcfs-01.dominio.local
            responsible mail addr = hostmaster
            serial  = 41
            refresh = 900 (15 mins)
            retry   = 600 (10 mins)
            expire  = 86400 (1 day)
            default TTL = 3600 (1 hour)
    SendRequest(), len 28
        HEADER:
            opcode = QUERY, id = 3, rcode = NOERROR
            header flags:  query, want recursion
            questions = 1,  answers = 0,  authority records = 0,  additional = 0
        QUESTIONS:
            google.com, type = A, class = IN
    DNS request timed out.
        timeout was 2 seconds.
    timeout (2 secs)
    SendRequest failed
    *** Request to srv-dcfs-01.dominio.local timed-out
    As you can see highlighted in bold, the problem remains in the "recursive query to other DNS Servers" check.
    Maybe is better to put the issue on the "Windows Server General Forum" , because the issue has not nothing in common with the ISA Server, dont you?
    Thanks
    Best regards

  • Can't change DNS server setting on airport express

    new airport express, comcast cable ISP, i cannot change the DNS server settings, they are greyed out.  why  is there no way to change this?

    Mark-
    Did you get the AE to actually use the OpenDNS servers?  I have the new AE and Airport Utility 6.3.1 and while I can enter the OpenDNS server settings (208.67.222.222 and 208.67.220.220), they don't work.  When I use a Wi-Fi connected device (my iPhone, for example) it sill uses the Comcast DNS settings, totally ignoring the OpenDNS settings.  I don't know when they stopped working, but they worked in the past.  I've used the old Airport Utility as well (5.6) and it says the OpenDNS settings are active, but they aren't.
    I want to use the OpenDNS settings for Wi-Fi connected devices in my home for content filtering.  If anyone knows of a DOCSIS 3 cable modem that allows setting DNS servers, that would be an option too, but unfortunately, my Motorola SurfBoard SBG6580 does not.

Maybe you are looking for