How To Set a Static IP Address With PowerShell

In this blog post, I will show you how to assign and set a static IP address to a Windows 10 machine or Windows Server using PowerShell.


The NetIPAddress PowerShell module, which is included with PowerShell allows us to manage and configure the TCP\IP configuration of a Windows machine with PowerShell.

This option is very powerful because it allows us to programmatically set the IP address of a host using PowerShell, either remote or locally.


The PowerShell code \ script below will set the IP address of my machine with a static IP address, Default Gateway and a DNS server.

The code will assign the IP address to the network adapter and will exclude all virtual and VPN adapter.

$ip = ""
$prefix = "24"
$GW = ""
$DNS = ""
$adapter = (Get-NetAdapter).ifIndex
New-NetIPAddress -IPAddress $ip -PrefixLength $prefix `
-InterfaceIndex $adapter -DefaultGateway $GW