How to Change Default gateway and subnet mask in PowerShell


Pretty much as the title says.

as it is now there is no default gateway appearing in PowerShell so I guess I’m adding a new one and not changing an old one. The subnet mask needs to change from to . Should this happen automatically when the IP address gets changed or when when the default gateway gets changed?

there doesn’t seem to be a lot of info on subnet mask that’s why I’m just assuming it should just change automatically. but I could be wrong


As far as I know Powershell does not need a separate IP configuration. It uses the existing IP stack of the underlying Windows. You might elaborate more in detail about the reason for your question.

When you are trying to change the IPAddress, SubnetMask/PrefixLength, DefaultGateway and DNSServer using PowerShell, that you need to add the addresses for each, it will not auto-populate.


PS C:> New-NetIPAddress -InterfaceIndex 12 -IPAddress -PrefixLength 24 -DefaultGateway
PS C:> Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses,


If this is a corporate environment, this is normally handled by your DHCP server.
Just do a release all on the IPAddress on the host and a renew or restart the computer.

If you are in a workgroup, then of course you need PSRemoting setup to use the Net-* cmldets to set what you are after, but even that, you need to be on the same IPRange for your workstation and the remote host.
If you are on your own workstation, just use the GUI to do this, unless you are saying you need to do this a lot then automation would be prudent.