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.
NetIPAddress
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.
Code
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 = "192.168.100.10" $prefix = "24" $GW = "192.168.100.1" $DNS = "192.168.100.10" $adapter = (Get-NetAdapter).ifIndex New-NetIPAddress -IPAddress $ip -PrefixLength $prefix ` -InterfaceIndex $adapter -DefaultGateway $GW