All I want to do is assign an IP address

This topic contains 3 replies, has 3 voices, and was last updated by  Rob 1 year, 4 months ago.

  • Author
  • #65394


    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.

  • #65427


    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
  • #65518

    Frank Tucker

    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 {$ -eq "ethernet"} | New-NetIPAddress -IPAddress -PrefixLength 24 -DefaultGateway 
  • #65769


    Thanks all. Yeah I had the options wrong. It's working now.

You must be logged in to reply to this topic.