Solved

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

Posted on 2014-11-18
1
307 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

New Windows 7 Installations take days for Windows-Updates to show up and install. This can easily be fixed. I have finally decided to write an article because this seems to get asked several times a day lately. This Article and the Links apply to…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

825 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