Solved

Need Powershell Script for NIC configuration

Posted on 2011-02-23
3
830 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 17

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 71

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
A brief introduction to what I consider to be the best editor for PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

713 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