How to Configure Network Settings with PowerShell on Windows Server 2022
PowerShell’s NetTCPIP, NetAdapter, and DnsClient modules provide a complete, scriptable interface for every network configuration task on Windows Server 2022 — from renaming adapters to setting static IP addresses, configuring DNS, managing routes, and testing connectivity. These cmdlets replaced the legacy netsh commands for most tasks and are idempotent by design, making them suitable for deployment scripts and configuration management. This guide covers every major network configuration scenario you will encounter administering Windows Server 2022.
Discovering Network Adapters
Before making any changes, identify the adapters present on the system. Get-NetAdapter lists all network interface cards, including virtual adapters created by Hyper-V, VPN clients, and loopback adapters.
# List all adapters with key properties
Get-NetAdapter | Select-Object Name, InterfaceIndex, Status, MacAddress, LinkSpeed
# Show only physical, connected adapters
Get-NetAdapter | Where-Object {$_.Status -eq "Up" -and $_.Virtual -eq $false}
# Get detailed adapter information including driver version
Get-NetAdapterAdvancedProperty -Name "Ethernet" | Select-Object DisplayName, DisplayValue
The InterfaceIndex (also called ifIndex) is the numeric identifier used internally. Many cmdlets accept either -InterfaceAlias (the human-readable name like “Ethernet” or “Ethernet 2”) or -InterfaceIndex. Using the alias is safer in scripts because the index can change after reboots or hardware changes, while the alias persists until you rename it.
Viewing Current IP Configuration
Get-NetIPConfiguration provides a summary equivalent to ipconfig /all but returns structured objects you can pipe and filter:
# Show all adapters with IP configuration
Get-NetIPConfiguration
# Show configuration for a specific adapter
Get-NetIPConfiguration -InterfaceAlias "Ethernet"
# Get just the IP addresses assigned to all adapters
Get-NetIPAddress | Select-Object InterfaceAlias, IPAddress, PrefixLength, AddressFamily, Type
# Show only IPv4 addresses
Get-NetIPAddress -AddressFamily IPv4 | Where-Object {$_.PrefixOrigin -ne "WellKnown"}
# View current DNS servers
Get-DnsClientServerAddress | Where-Object {$_.AddressFamily -eq 2} |
Select-Object InterfaceAlias, ServerAddresses
Assigning a Static IP Address
Use New-NetIPAddress to assign a static IP address to an adapter. Before assigning a static address, remove any existing addresses on that adapter to avoid IP conflicts.
# Remove an existing IP address (if any) before adding a new static one
Remove-NetIPAddress -InterfaceAlias "Ethernet" -Confirm:$false
# Remove the default gateway on the interface if it exists
Remove-NetRoute -InterfaceAlias "Ethernet" -DestinationPrefix "0.0.0.0/0" -Confirm:$false
# Assign a static IPv4 address with gateway
New-NetIPAddress `
-InterfaceAlias "Ethernet" `
-AddressFamily IPv4 `
-IPAddress 192.168.1.100 `
-PrefixLength 24 `
-DefaultGateway 192.168.1.1
# Assign a static IPv6 address
New-NetIPAddress `
-InterfaceAlias "Ethernet" `
-AddressFamily IPv6 `
-IPAddress 2001:db8::100 `
-PrefixLength 64 `
-DefaultGateway 2001:db8::1
To combine the address removal and assignment into a single operation, use Set-NetIPAddress — but only if an address already exists on the interface:
# Modify an existing IP address in place (does not create a new address)
Set-NetIPAddress `
-InterfaceAlias "Ethernet" `
-IPAddress 192.168.1.101 `
-PrefixLength 24
Note the difference: New-NetIPAddress creates a new address (and fails if one already exists on the same interface unless you use -SkipAsSource), while Set-NetIPAddress modifies an existing one. For reliable scripted deployment, always do Remove then New.
Configuring DNS Client Settings
Set-DnsClientServerAddress sets the DNS server list for an adapter. Specify multiple servers as a comma-separated array — they are tried in order.
# Set primary and secondary DNS servers
Set-DnsClientServerAddress `
-InterfaceAlias "Ethernet" `
-ServerAddresses @("192.168.1.10", "192.168.1.11")
# Add a tertiary DNS server (you must re-specify the full list)
Set-DnsClientServerAddress `
-InterfaceAlias "Ethernet" `
-ServerAddresses @("192.168.1.10", "192.168.1.11", "8.8.8.8")
# Reset to DHCP-assigned DNS (removes static DNS)
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ResetServerAddresses
# Set the primary DNS suffix for this computer
Set-DnsClient -InterfaceAlias "Ethernet" -ConnectionSpecificSuffix "corp.example.com"
# Configure the global DNS suffix search list
Set-DnsClientGlobalSetting -SuffixSearchList @("corp.example.com", "example.com")
# Flush the DNS resolver cache
Clear-DnsClientCache
# View the current DNS cache
Get-DnsClientCache | Select-Object Entry, Data, TimeToLive | Format-Table -AutoSize
Managing Routing with Get-NetRoute and New-NetRoute
Static routes are needed when a server has multiple network interfaces and traffic to certain subnets must go through a specific gateway.
# View all current routes
Get-NetRoute | Where-Object {$_.AddressFamily -eq "IPv4"} |
Select-Object DestinationPrefix, NextHop, InterfaceAlias, RouteMetric |
Sort-Object DestinationPrefix | Format-Table -AutoSize
# Add a static route to the 10.20.0.0/16 network via a specific gateway
New-NetRoute `
-InterfaceAlias "Ethernet" `
-DestinationPrefix "10.20.0.0/16" `
-NextHop 192.168.1.254 `
-RouteMetric 10
# Add a host route (a route to a single IP address, /32)
New-NetRoute `
-InterfaceAlias "Ethernet" `
-DestinationPrefix "10.30.5.1/32" `
-NextHop 192.168.1.254
# Remove a static route
Remove-NetRoute `
-InterfaceAlias "Ethernet" `
-DestinationPrefix "10.20.0.0/16" `
-Confirm:$false
# Change the metric on a route
Set-NetRoute `
-InterfaceAlias "Ethernet" `
-DestinationPrefix "0.0.0.0/0" `
-RouteMetric 5
Configuring Advanced Adapter Properties
Get-NetAdapterAdvancedProperty and Set-NetAdapterAdvancedProperty control settings that are normally only accessible through the adapter’s Properties dialog in Device Manager — jumbo frames, receive-side scaling, interrupt moderation, offload settings, and VLAN tagging.
# View all advanced properties for an adapter
Get-NetAdapterAdvancedProperty -Name "Ethernet"
# Enable Jumbo Frames (value varies by driver; 9014 is common for Intel)
Set-NetAdapterAdvancedProperty `
-Name "Ethernet" `
-RegistryKeyword "JumboPacket" `
-RegistryValue 9014
# Enable Receive Side Scaling (RSS)
Set-NetAdapterRss -Name "Ethernet" -Enabled $true
# Set the number of RSS queues
Set-NetAdapterRss -Name "Ethernet" -NumberOfReceiveQueues 4
# Configure a VLAN ID on an adapter
Set-NetAdapterAdvancedProperty `
-Name "Ethernet" `
-RegistryKeyword "VlanID" `
-RegistryValue 100
# Disable energy-efficient Ethernet (can cause intermittent connectivity issues)
Set-NetAdapterAdvancedProperty `
-Name "Ethernet" `
-RegistryKeyword "EEE" `
-RegistryValue 0
Disabling, Enabling, and Renaming Adapters
# Disable a network adapter
Disable-NetAdapter -Name "Ethernet 2" -Confirm:$false
# Enable a network adapter
Enable-NetAdapter -Name "Ethernet 2"
# Rename an adapter (the new name persists across reboots)
Rename-NetAdapter -Name "Ethernet" -NewName "LAN-Production"
Rename-NetAdapter -Name "Ethernet 2" -NewName "LAN-Management"
# Verify the rename
Get-NetAdapter | Select-Object Name, InterfaceIndex, Status
Renaming adapters to meaningful names (“LAN-Production”, “iSCSI-Storage”, “Heartbeat”) before assigning IP addresses makes scripts and firewall rules much easier to read and maintain. Do the rename immediately after a fresh OS installation before configuring anything else.
Testing Connectivity with Test-NetConnection
Test-NetConnection is a versatile diagnostic cmdlet that combines ping, traceroute, and TCP port testing into a single tool.
# Basic ping test
Test-NetConnection -ComputerName 8.8.8.8
# Test a specific TCP port (useful for testing firewall rules)
Test-NetConnection -ComputerName sql-server01 -Port 1433
# Test HTTPS connectivity
Test-NetConnection -ComputerName www.example.com -Port 443
# Traceroute to a destination
Test-NetConnection -ComputerName 8.8.8.8 -TraceRoute
# Test RDP port on a remote server
Test-NetConnection -ComputerName srv-rds01 -Port 3389 |
Select-Object ComputerName, RemotePort, TcpTestSucceeded, PingSucceeded
The TcpTestSucceeded property tells you whether a TCP connection was established, regardless of what the application sends after connecting. If PingSucceeded is True but TcpTestSucceeded is False, the host is reachable but the specific port is blocked by a firewall or the service is not listening. If both are False, there is a network or routing problem.
DNS Resolution with Resolve-DnsName
Resolve-DnsName queries DNS and returns structured result objects — unlike nslookup, the output can be piped and filtered in scripts.
# Resolve a hostname to IP addresses
Resolve-DnsName -Name "www.example.com"
# Query a specific DNS server
Resolve-DnsName -Name "www.example.com" -Server 8.8.8.8
# Look up an MX record
Resolve-DnsName -Name "example.com" -Type MX
# Look up a TXT record (useful for verifying SPF/DKIM)
Resolve-DnsName -Name "example.com" -Type TXT
# Reverse DNS lookup (PTR record)
Resolve-DnsName -Name "192.168.1.10" -Type PTR
# Check if an SRV record exists (useful for AD diagnostics)
Resolve-DnsName -Name "_ldap._tcp.dc._msdcs.corp.example.com" -Type SRV
Configuring Multiple IP Addresses on a Single Adapter
Windows Server 2022 supports multiple IP addresses on a single physical adapter, which is useful for hosting multiple SSL certificates on IIS without additional NICs or for migrating IP addresses during server transitions.
# Add a second IP address to an adapter (note: no -DefaultGateway on secondary addresses)
New-NetIPAddress `
-InterfaceAlias "LAN-Production" `
-AddressFamily IPv4 `
-IPAddress 192.168.1.101 `
-PrefixLength 24 `
-SkipAsSource $false
# Add a third IP address
New-NetIPAddress `
-InterfaceAlias "LAN-Production" `
-AddressFamily IPv4 `
-IPAddress 192.168.1.102 `
-PrefixLength 24
# Confirm all addresses on the adapter
Get-NetIPAddress -InterfaceAlias "LAN-Production" -AddressFamily IPv4 |
Select-Object IPAddress, PrefixLength, Type
Complete Network Configuration Script
The following script combines all the steps above into a complete network configuration routine suitable for deploying a new server. Adjust the variables at the top for your environment:
# --- Configuration variables ---
$AdapterName = "Ethernet"
$NewAdapterName = "LAN-Production"
$IPAddress = "192.168.1.100"
$PrefixLength = 24
$Gateway = "192.168.1.1"
$DNS1 = "192.168.1.10"
$DNS2 = "192.168.1.11"
$DNSSuffix = "corp.example.com"
# --- Rename the adapter ---
Rename-NetAdapter -Name $AdapterName -NewName $NewAdapterName
# --- Remove existing IP configuration ---
$existing = Get-NetIPAddress -InterfaceAlias $NewAdapterName -AddressFamily IPv4 -ErrorAction SilentlyContinue
if ($existing) {
Remove-NetIPAddress -InterfaceAlias $NewAdapterName -Confirm:$false
}
Remove-NetRoute -InterfaceAlias $NewAdapterName -DestinationPrefix "0.0.0.0/0" -Confirm:$false -ErrorAction SilentlyContinue
# --- Assign static IP ---
New-NetIPAddress `
-InterfaceAlias $NewAdapterName `
-AddressFamily IPv4 `
-IPAddress $IPAddress `
-PrefixLength $PrefixLength `
-DefaultGateway $Gateway
# --- Set DNS servers ---
Set-DnsClientServerAddress `
-InterfaceAlias $NewAdapterName `
-ServerAddresses @($DNS1, $DNS2)
# --- Set DNS suffix ---
Set-DnsClient -InterfaceAlias $NewAdapterName -ConnectionSpecificSuffix $DNSSuffix
# --- Flush DNS cache ---
Clear-DnsClientCache
# --- Verify the configuration ---
Get-NetIPConfiguration -InterfaceAlias $NewAdapterName
Get-DnsClientServerAddress -InterfaceAlias $NewAdapterName
# --- Test connectivity ---
Write-Host "Testing gateway connectivity..."
Test-NetConnection -ComputerName $Gateway
Write-Host "Testing DNS resolution..."
Resolve-DnsName -Name $DNSSuffix -Server $DNS1
Run this script during initial server provisioning, and the server will have a complete, tested network configuration in under 30 seconds. Store the script in version control with per-server variable files to maintain a reproducible infrastructure configuration baseline.