Categories

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>