Skip to content

How to set static & DHCP IP addresses in PowerShell

Brock
Brock Bingham|Updated April 20, 2026
Illustration of block with Powershell logo
Illustration of block with Powershell logo

TL;DR: PowerShell lets you set a static IP address, enable DHCP, or reset IP settings on Windows by using built-in networking cmdlets like Get-NetAdapter, Set-NetIPInterface, and New-NetIPAddress. In practice, that means you can script common network changes instead of clicking through Windows menus.

Setting a static IP address or switching back to DHCP is a routine Windows admin task, but doing it through the GUI gets old fast. PowerShell gives you a cleaner, repeatable way to make those changes without digging through adapter settings every time.

In this guide, we’ll cover the core cmdlets and scripts you can use to manage IP settings on Windows, including how to assign a static IP, enable DHCP, and clear out old IPv4 configuration before applying new values.

PowerShell cmdlets for managing IP settings on Windows

PowerShell has hundreds of cmdlets that let you control everything from services to registry settings, and that includes network configuration. Here are the core PowerShell cmdlets you’ll use to manage network configuration on Windows.

Get-NetAdapter: The Get-NetAdapter cmdlet returns information about your network adapters, including Ethernet, Wi-Fi, and Bluetooth interfaces.

PowerShell window displaying output from the Get-NetAdapter cmdlet, listing network adapters including Ethernet, Bluetooth, USB Ethernet, and Wi-Fi, along with their status, interface index, MAC address, and link speed.

If you have multiple network adapters, you need to identify which network adapter you wish to view or modify by name, interface index, status, etc. For systems with one adapter, you can typically get this by using only Get-NetAdapter with no extra parameters. Please adjust this to suit your environment.

As an example, on one of my test systems, I have two network adapters. One is active, and one is inactive. I can grab only the active network adapter by using the command Get-NetAdapter | ? {$_.Status -eq “up”}.

Get-NetIPConfiguration: This cmdlet returns the network configuration (interfaces, IP addresses, and DNS servers).

PowerShell window displaying the output of the Get-NetIPConfiguration cmdlet, showing IP configuration details for multiple network interfaces, including Wi-Fi, Ethernet 2, and Bluetooth. Details include interface aliases, IP addresses (IPv4 and IPv6), default gateways, DNS servers, and adapter statuses.

Get-NetIPInterface: The Get-NetIPInterface cmdlet returns the internet protocol (IP) interfaces, which can include both IPv4 and IPv6 addresses and their associated configurations.

PowerShell output from Get-NetIPInterface, showing network interfaces with DHCP status, connection state, and address family for IPv4 and IPv6.

Set-NetIPInterface: The Set-NetIPInterface lets you modify IP interface settings, such as enabling or disabling DHCP.

Set-DnsClientServerAddress: The Set-DnsClientServerAddress cmdlet lets you set the DNS servers associated with a particular network interface.

Remove-NetRoute: The Remove-NetRoute cmdlet lets you modify IP routes in the routing table, including wiping out all routes.

New-NetIPAddress: The New-NetIPAddress allows you to create and configure an IPv4 and IPv6 addresses on a network adapter.

PowerShell scripts for static IP and DHCP configuration

Before applying new values, these scripts remove the adapter’s current IPv4 address and default gateway. That makes them a practical way to reset IP settings in PowerShell before switching to a new configuration.

With that out of the way, here are the PowerShell scripts to set a static IP address or enable DHCP on Windows.

How to set a static IP address in PowerShell

This PowerShell script sets a static IPv4 address, subnet prefix, default gateway, and DNS server on the active network adapter.

$IP = "10.10.10.10" $MaskBits = 24 # This means subnet mask = 255.255.255.0 $Gateway = "10.10.10.1" $Dns = "10.10.10.100" $IPType = "IPv4" # Retrieve the network adapter that you want to configure $adapter = Get-NetAdapter | ? {$_.Status -eq "up"} # Remove any existing IP, gateway from our ipv4 adapter If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) { $adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false } If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) { $adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false } # Configure the IP address and default gateway $adapter | New-NetIPAddress ` -AddressFamily $IPType ` -IPAddress $IP ` -PrefixLength $MaskBits ` -DefaultGateway $Gateway # Configure the DNS client server IP addresses $adapter | Set-DnsClientServerAddress -ServerAddresses $DNS

How to enable DHCP in PowerShell

This PowerShell script enables DHCP for IPv4, removes the existing default gateway, and resets DNS servers to automatic.

$IPType = "IPv4" $adapter = Get-NetAdapter | ? {$_.Status -eq "up"} $interface = $adapter | Get-NetIPInterface -AddressFamily $IPType If ($interface.Dhcp -eq "Disabled") { # Remove existing gateway If (($interface | Get-NetIPConfiguration).Ipv4DefaultGateway) { $interface | Remove-NetRoute -Confirm:$false } # Enable DHCP $interface | Set-NetIPInterface -DHCP Enabled # Configure the DNS Servers automatically $interface | Set-DnsClientServerAddress -ResetServerAddresses }

How to switch between DHCP and a static IP in PowerShell

You can switch a Windows adapter between DHCP and a static IP in PowerShell by using Set-NetIPInterface and New-NetIPAddress. Use DHCP when the device should receive settings automatically, or use a static configuration when the device needs a fixed address.

How to switch from a static IP to DHCP in PowerShell

To disable a static IP address on a network adapter, you can set the interface to obtain an IP address automatically (DHCP).

$interface | Set-NetIPInterface -InterfaceAlias "YourNetworkAdapterName" -Dhcp Enabled 

Replace "YourNetworkAdapterName" with the actual name or alias of your network adapter. This command configures the interface to obtain an IP address automatically from a DHCP server.

How to disable DHCP and set a static IP in PowerShell

To disable DHCP and set a static IP address on a network adapter, you can use the following PowerShell commands:

$interface | Set-NetIPInterface -InterfaceAlias "YourNetworkAdapterName" -Dhcp Disabled $adapter | New-NetIPAddress -InterfaceAlias "YourNetworkAdapterName" -IPAddress "YourStaticIPAddress" -PrefixLength "YourSubnetPrefixLength" -DefaultGateway "YourDefaultGatewayIP" 

Replace "YourNetworkAdapterName" with the actual name or alias of your network adapter, "YourStaticIPAddress" with the desired static IP address you want to assign, "YourSubnetPrefixLength" with the subnet prefix length (e.g., 24 for a typical subnet mask of 255.255.255.0), and "YourDefaultGatewayIP" with the IP address of your default gateway.

Final thoughts

PowerShell provides a powerful and efficient way to manage network configurations, allowing you to automate tasks and reduce manual effort. Whether you're setting static IP addresses, enabling DHCP, or resetting network settings, these cmdlets and scripts can streamline your workflow.

This is still just scratching the surface of what’s available. For a broader list of networking and TCP/IP cmdlets, check out the PowerShell Commands Library.

And this goes without saying — consider exploring PDQ's suite of tools, including PDQ Connect and PDQ Deploy & Inventory, to further enhance your system administration capabilities.

Brock
Brock Bingham

Brock Bingham is a systems administrator with 15 years of experience managing endpoints and servers, with a strong focus on automation, patching, security, and maintaining stable environments at scale. After years of hands-on IT work, he now creates content and teaches, helping other admins learn through practical, real-world guidance.

Related articles