and it’s for some reason being ridiculously difficult! I know I’ve been able to do this before, so there is either something about this OS (2k12r2 and intel NIC drivers) or something changed with powershell and I can’t figure it out.
I’ve tried set-netipaddress and new-netipaddress for the interface, using either name, alias, or index, and I always get an error saying either “the object already exists” or “no matching MSFT_netipaddress objects found by CIM query…”
Anyone know whats going on here? This should not be this difficult.
I remember struggling with various errors when setting IPv4 addresses previously. I came up with a way that seems to work, unfortunately I don’t remember why I had to do it this way …
First I would reset the addresses for the interface and use DHCP:
Remove-NetRoute -InterfaceAlias $Interface -AddressFamily IPv4 Set-NetIPInterface -InterfaceAlias $Interface -Dhcp Enabled -AddressFamily IPv4 Set-DnsClientServerAddress -InterfaceAlias $Interface -ResetServerAddresses
Then I would go on to set the primary IPv4 address and DNS server addresses:
New-NetIPAddress -InterfaceAlias $Interface -IPAddress $Ip1 -DefaultGateway $Gateway -AddressFamily IPv4 -PrefixLength 24 Set-DnsClientServerAddress -InterfaceAlias $Interface -ServerAddresses $DNSServer
Finally to set additional addresses for the same interface I had to use the SkipAsSource parameter:
New-NetIPAddress -InterfaceAlias $Interface -IPAddress $Ip2 -AddressFamily IPv4 -PrefixLength 24 -SkipAsSource $True
I think you maybe forgetting to set a -PrefixLength along with your -IPAddress when using new-netipaddress
Also try to | which interface you wish to set to new-netipaddress
Get-NetAdapter | Where-Object {$_.name -eq "ethernet"} | New-NetIPAddress -IPAddress 172.31.10.222 -PrefixLength 24 -DefaultGateway 172.31.10.222
Thanks all. Yeah I had the options wrong. It’s working now.