PowerShell for Windows Admins

May 20 2012   4:34AM GMT

TCP/IP Alternative Configurations: pt IV reset to static address



Posted by: Richard Siddaway
Tags:
Network
PowerShell
WMI

At some stage we may need to reset our NIC back to having a static address

$index = 7            
            
$nic = Get-WmiObject -Class Win32_NetworkAdapterConfiguration `
-Filter "Index=$index"             
            
$ipaddress = @("10.10.54.202")            
$subnet = @("255.255.255.0")            
Invoke-WmiMethod -InputObject $nic -Name EnableStatic -ArgumentList $ipaddress, $subnet            
            
$dnsserver = "10.10.54.201"            
$nic.SetDNSServerSearchOrder($dnsserver)            
            
#Invoke-WmiMethod -InputObject $nic -Name SetDNSServerSearchOrder -ArgumentList $dnsserver

We get the configuration of the NIC and use the EnableStatic method to set the address and subnet

The SetDNSServerSearchOrder method is used to set the DNS server.

Notice I haven’t been able to use Invoke-WmiMethod at this point – I’ve had to call the method directly on the object. There appears to be an issue with the formatting of the DNS server addresses as Invoke-WmiMethod complains that the argument has to be an array.

This is under investigation.

More on using WMI with PowerShell can be found in PowerShell and WMI. Chapter 11 covers network adapters in detail.  More details from www.manning.com/powershellandwmi

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: