Solved

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

We recently had an issue where out of nowhere, end users started indicating that their logins to our terminal server were just showing a "blank screen." After checking the usual suspects -- profiles, shell=explorer.exe in the registry, userinit.exe,…
If you migrate a Terminal Server licenses server inside the 2008 server family, you can takte advantage of the build-in migration tool. If you like to migrate an older 2003 Server (and the installed client CALs) to a 2008 R2 server for example, you …
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…

734 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