Solved

Script to Change Subnet & Default Gateway for windows Server 2k8

Posted on 2014-11-18
1
302 Views
Last Modified: 2014-12-14
hi,

We plan to change our network design and we want to run a script that will make things faster for us.

We want the script to run with the following conditions:
===============================================
1. It will keep the current Static IP Address that is configured and use it [it will not change].
2. Change the subnet mask to a new subnet mask we'll insert it.
3. change the default gateway address to a new address we'll insert it.

for OS: Windows Server 2008

we want that the script will be fully automatic (without the need to answer any questions).

thanks.
0
Comment
Question by:Tufin
1 Comment
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 500 total points
ID: 40450618
You may use the following powershell code.

You need to feed the servername,subnetmask and default gateway in a csv file in below format.

Server,subnet,gateway
server1,x.x.x.x,x.x.x.x
server2,x.x.x.x,x.x.x.x

foreach($server in import-csv input.csv){
$nic = Get-WmiObject win32_networkadapterconfiguration -ComputerName $server.server | where {$_.ipenabled = 'true'}
$IP = $nic.IPaddress
$nic.EnableStatic($IPaddress,$server.subnet)
$nic.SetGateways($server.gateway,1)
}

Open in new window



If you have same subnet and gateway values for all servers then you need to just give the first column in the csv file and use the following code

$subnet = x.x.x.x
$gateway = x.x.x.x
foreach($server in import-csv input.csv){
$nic = Get-WmiObject win32_networkadapterconfiguration -ComputerName $server.server | where {$_.ipenabled = 'true'}
$IP = $nic.IPaddress
$nic.EnableStatic($IPaddress,$subnet)
$nic.SetGateways($gateway,1)
}

Open in new window

0

Featured Post

Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
OfficeMate Freezes on login or does not load after login credentials are input.
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

911 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

23 Experts available now in Live!

Get 1:1 Help Now