Solved

Need Powershell Script for NIC configuration

Posted on 2011-02-23
3
823 Views
Last Modified: 2012-05-11
I'm looking for a powershell script that will configure a Windows Server 2008 NIC.  

The script should prompt me to enter the nic configuration information, such as IP address, subnet mask, gateway, primary dns, secondary dns, wins, and so forth.  The script should then configure the nic with the input that I provided.  Ideally, it would then issue an automatic reboot of the server.

I have a lot of virtual servers that are being moved to a new subnet.  Once they are moved to the new subnet, I'm going to access the machine using the VMware console.  I'm then going to log in and reconfigure the nics.  This is why I ask for help with a script.

Any help or useful suggestions will be greatly appreciated.


0
Comment
Question by:xi2pay
3 Comments
 
LVL 16

Accepted Solution

by:
Learnctx earned 500 total points
ID: 34966902
Try this.

Usage: Set-Network -ip 1.1.1.1 -mask 255.255.255.0 -dns1 1.1.1.2 -dns2 1.1.1.3 -gateway 1.1.1.254
function Set-Network {

	param(
		[string]$ip,
		[string]$mask,
		[string]$gateway,
		[string]$dns1,
		[string]$dns2,
	)

	if ($dns1 -And $dns2)
	{
		$dns = "$($dns1),$($dns2)"
	}
	elseif ($dns1)
	{
		$dns = $dns1
	}


	$objNetAdaConf = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IPEnabled='True'"
	[void]$objNetAdaConf.EnableStatic($ip, $mask)
	[void]$objNetAdaConf.SetGateways($gateway)
	[void]$objNetAdaConf.SetDNSServerSearchOrder($dns)
}

Open in new window

0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 35687958
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

21 Experts available now in Live!

Get 1:1 Help Now