If you want to add a secondary IP Address without using the Change Adapter Options in the GUI ( especially on Windows Core servers ) you could use sconfig or simply add the IP address with PowerShell.
In my case, I wanted to add a secondary IP address to a certain interface on some Windows Server Core servers. Unfortunately, an Invalid Index error was thrown when I chose the appropriate interface under sconfig – Network Settings:
However, I faced this error a couple of months ago already when I wanted to Disable IPv6 in my test lab.
Because this time it was production servers I didn’t want to change any settings while adding secondary IP addresses to the servers. The only option was to add a secondary IP address via PowerShell.
… and here we go:
Add Secondary IP Address to Network Interface:
List Network Interfaces with name and Interface Index
Display existent IPs on chosen Network Interface
Get-NetAdapter -ifIndex ifIndex Number | Get-NetIPAddress | select IPAddress | ftTo display only IPv4 addresses:
Get-NetAdapter -ifIndex ifIndex Number | Get-NetIPAddress | where {$_.AddressFamily –eq “IPv4”} | select IPAddress
Add new IP address
The command adds the IP address to the ActiveStore and the Persistent Store.
You can read more about the PolicyStore values here.
Verify that add a secondary IP address was successful
Thats all. You don’t need to specify a default Gateway since this has most likely be done already with the initial IP address.
Remove IP Address from Network Interface:
List Network Interfaces with name and Interface Index
Display existent IP addresses that can be removed on chosen Network Interface
Get-NetAdapter -ifIndex ifIndex Number | Get-NetIPAddress | where {$_.AddressFamily –eq “IPv4”} | select IPAddress
Copy IP address to remove from the output.
Remove IP address
Get-NetIPAddress –IPAddress IPAddressToRemove –InterfaceIndex ifIndex Number | Remove-NetIPAddressYou will need to confirm it for both PolicyStores.
Otherwise you could use the command with -Confirm:$false
add secondary IP address verify
I have compiled the above steps in a script to make it more convenient: