Solved

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

Posted on 2014-11-18
1
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

I was asked if I could set up a fax machine so that incoming faxes were delivered to people's Exchange inboxes and so that they could send faxes from their desktops without needing to print the document first.  I knew it was possible but I had no id…
Redirected folders in a windows domain can be quite useful for a number of reasons, one of them being that with redirected application data, you can give users more seamless experience when logging into different workstations.  For example, if a use…
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…

735 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