PowerShell for Windows Admins

May 20 2012   4:34AM GMT

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

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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 = @("")            
$subnet = @("")            
Invoke-WmiMethod -InputObject $nic -Name EnableStatic -ArgumentList $ipaddress, $subnet            
$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.

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:

Share this item with your network: