Windows: How to remove and re-add IPs with skipassource true flag

  Windows

) Download three optional hot fixes from Microsoft:
Windows 2008 R2:
KB2386184: This is a patch adding a feature to exclude IP addresses from the list of IP addresses allowed as the outgoing IP address (e. source). This is the key patch allowing us to “select” the primary IP address.
KB2554859: KB2386184 was buggy and seems to be a quickfix. This hotfix fixes a bug where the GUI used to manage IP addresses on the server clears the configurations made using the new feature added by KB2386184 .
KB2551090: Apparently KB2386184 created another bug where you couldn’t select IP addresses excluded as outgoing IP address. This fixed that.

from: http://www.aip.im/2013/01/how-to-set-the-primary-ip-address-of-a-windows-server-2008-r2/

Windows 2008:
https://support.microsoft.com/en-us/help/975808/all-ip-addresses-are-registered-on-the-dns-servers-when-the-ip-addresses-are-assigned-to-one-network-adapter-on-a-computer-that-is-running-windows-server-2008-sp2-or-windows-vista-sp2

) Get list of existing IPs

netsh interface ip show config name="Local Area Connection" |findstr "IP Address" > ips.txt

Where “Local Area Connection” is the name of your network adapter

) Edit list to make it list just the IPs and also remove the main ‘primary’ IP

) Remove IPs

FOR /F %G IN (ips.txt) DO netsh int ipv4 delete address "Local Area Connection" addr=%G

) Re-add IPs with skipassource=true

FOR /F %G IN (ips.txt) DO netsh int ipv4 add address "Local Area Connection" %G 255.255.255.0 skipassource=true