Solved

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

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

You might have come across a situation when you have Exchange 2013 server in two different sites (Production and DR). After adding the Database copy in ECP console it displays Database copy status unknown for the DR exchange server. Issue is strange…
The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This tutorial will give a an overview on how to deploy remote agents in Backup Exec 2012 to new servers. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as connecting to a remote Back…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

747 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

10 Experts available now in Live!

Get 1:1 Help Now