none
script to change default gateway ip

    Question

  • Hi all,

    Due to our network change, we need to change over 50 servers' default gateway to the new IP address.  These servers are Windows 2003, windows 2008 & Windows 2008 R2.

    Is there a way to change through batch or script the default gateway IP (only gateway) on these servers instead of logging onto each one to change it?

    Thank you very much!

    Wednesday, February 06, 2013 9:25 PM

Answers

  • You should be able to do something like this:

    netsh interface ip set address * gateway=192.168.0.2 gw=1

    If you had a list of servers that you wanted to change, and they all had powershell loaded, you could something like this:

    $servers = get-content c:\server-list.txt
    Foreach ($server in $servers)
        $cmd = "netsh interface ip set address * gateway=192.168.0.2 gw=1"
        invoke-command $server -scriptblock $cmd
    }



    Thomas Lee <DoctorDNS@Gmail.Com>

    Sunday, February 24, 2013 10:32 AM
    Moderator

All replies

  • Have you searched the script repository? (There is a link right at the top of this page.)

    Bill

    Thursday, February 07, 2013 5:22 PM
    Moderator
  • You should be able to do something like this:

    netsh interface ip set address * gateway=192.168.0.2 gw=1

    If you had a list of servers that you wanted to change, and they all had powershell loaded, you could something like this:

    $servers = get-content c:\server-list.txt
    Foreach ($server in $servers)
        $cmd = "netsh interface ip set address * gateway=192.168.0.2 gw=1"
        invoke-command $server -scriptblock $cmd
    }



    Thomas Lee <DoctorDNS@Gmail.Com>

    Sunday, February 24, 2013 10:32 AM
    Moderator