How to replace an existing static IP address with PowerShell

Starting with Windows Server 2012, you can now handle directly the IP configuration with PowerShell cmdlets.

Unfortunately, there is no cmdlet which directly updates an already existing IP address. You have to use four of them.

Please be aware that you will disconnect yourself from the computer if you do this operation remotely. This won’t happen if you use PowerShell Direct or a VM console.

Main steps

  1. Find the index of the interface hosting the current IP address
    Get-NetIPAddress -IPAddress ''

  2. Remove this IP address from the persistent store.
    Remove-NetIPAddress -IPAddress ''

  3. Create a new IP address entry
    New-NetIPAddress -InterfaceIndex 12 -AddressFamily IPv4 -IPAddress '' -PrefixLength 24

  4. If the gateway is different from the former one, remove it, and set a new one
    Remove-NetRoute -InterfaceIndex 12 -NextHop
    New-NetRoute -InterfaceIndex 12 -DestinationPrefix '' -AddressFamily IPv4 -NextHop '' -RouteMetric 0

  5. If the DNS server has changed, set the interface’s DNS server
    Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses

More about

An explanation of the Automatic Metric feature for IPv4 routes (Microsoft Support)

IP Routing Table (Microsoft Technet)

Subnets and Subnet Masks (Microsoft Technet)

NetTCPIP cmdlets (Microsoft Docs)

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s