I recently had to change the subnet mask on a bunch of servers, and was initially planning on logging in and updating, but after a bit of research found that it is pretty easy to do using powershell. However, the piece that took a little thought and planning, in the powershell Set-NetIPAddress command we need to pass the network adapter alias. While this is pretty consistent across servers, there is always something that is a little different. After adding and replacing NIC’s, they aren’t all Ethernet, or Ethernet 2

I came up with a two-step script to so this. First, based on IP address, it looks up the network adapter alias, and finally, changes the netmask. The code I used is below.

$Alias = (Get-NetIPAddress -IPAddress '192.168.9.*').InterfaceAlias
Set-NetIPAddress -InterfaceAlias $Alias -PrefixLength 24

In the example above, we are changing the subnet mask on the adapter with a 192.168.9.x IP to a /24 subnet mask.

This made the process quick and easy, taking under two minutes to change the netmask across close to 50 servers.