http://get-powershell.com/post/2008/08/13/PowerShell-Function-Set-IPAddress.aspx
1: function Set-IPAddress {
2: param( [string]$networkinterface,
3: [string]$ip,
4: [string]$mask,
5: [string]$gateway,
6: [string]$dns1,
7: [string]$dns2,
8: [string]$registerDns = "TRUE"
9: )
10:
11:
12: #Start writing code here
13: $dns = $dns1
14: if($dns2){$dns ="$dns1,$dns2"}
15: $index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex
16: $NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}
17: $NetInterface.EnableStatic($ip, $mask)
18: $NetInterface.SetGateways($gateway)
19: $NetInterface.SetDNSServerSearchOrder($dns)
20: $NetInterface.SetDynamicDNSRegistration($registerDns)
21:
22: }