Solved

Need Powershell Script for NIC configuration

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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