PowerShell Commands for Network Troubleshooting

PowerShell showing network troubleshooting commands and outputs: Test-Connection, Test-NetConnection, Get-NetAdapter, ipconfig /all, Get-NetIPAddress, Resolve-DnsName, ping results.

PowerShell Commands for Network Troubleshooting
SPONSORED

Sponsor message — This article is made possible by Dargslan.com, a publisher of practical, no-fluff IT & developer workbooks.

Why Dargslan.com?

If you prefer doing over endless theory, Dargslan’s titles are built for you. Every workbook focuses on skills you can apply the same day—server hardening, Linux one-liners, PowerShell for admins, Python automation, cloud basics, and more.


Network connectivity issues can bring productivity to a grinding halt, whether you're managing enterprise infrastructure or troubleshooting your home office setup. When websites won't load, file shares become inaccessible, or applications fail to connect to remote services, the frustration is immediate and the pressure to resolve problems intensifies. Understanding how to diagnose and resolve these issues quickly separates competent administrators from those who struggle through trial-and-error approaches.

PowerShell has evolved into the command-line interface of choice for Windows system administrators, offering powerful network diagnostic capabilities that go far beyond traditional command prompt tools. This Microsoft scripting environment provides both immediate troubleshooting commands and the ability to create sophisticated diagnostic scripts that can identify patterns, automate testing, and document network behavior across complex infrastructures.

Throughout this exploration of PowerShell network troubleshooting techniques, you'll discover essential commands that diagnose connectivity problems, verify DNS resolution, test port availability, and analyze network configuration. You'll learn practical approaches to common scenarios, understand how to interpret command output effectively, and gain the confidence to tackle network issues systematically rather than randomly trying solutions until something works.

Essential Connectivity Testing Commands

The foundation of network troubleshooting begins with verifying basic connectivity between systems. PowerShell provides several commands that test whether network packets can successfully travel from your computer to a destination and return. These fundamental tests help you quickly determine whether a problem exists at the network layer or somewhere higher in the technology stack.

Testing Basic Network Reachability

The Test-Connection command serves as PowerShell's modern replacement for the classic ping utility, offering enhanced functionality and PowerShell-friendly output. This command sends Internet Control Message Protocol (ICMP) echo requests to a target system and reports whether responses are received, along with timing information that indicates network performance.

When you execute Test-Connection with a destination hostname or IP address, PowerShell sends four packets by default and displays detailed information about each response. The command reports the source computer, destination, packet size, response time in milliseconds, and whether each packet successfully reached its destination. This information immediately tells you whether basic network connectivity exists and provides insight into network latency.

Test-Connection -ComputerName google.com -Count 4

For scripting purposes, you can use the -Quiet parameter to receive a simple boolean result—True if the target responds, False if it doesn't. This approach works perfectly in conditional logic where you need to make decisions based on connectivity status without processing detailed output.

if (Test-Connection -ComputerName 192.168.1.1 -Count 2 -Quiet) { Write-Host "Gateway is reachable" }

"The difference between a good troubleshooter and a great one isn't just knowing the commands—it's understanding what the results actually mean and what they tell you about where the problem really lies."

Continuous Monitoring and Advanced Testing

When dealing with intermittent connectivity issues, continuous monitoring becomes essential. The -Continuous parameter transforms Test-Connection into a persistent monitoring tool that sends packets indefinitely until you press Ctrl+C to stop execution. This approach helps identify patterns in network instability, such as periodic packet loss or latency spikes that occur at specific intervals.

Test-Connection -ComputerName 10.0.0.5 -Continuous

The Test-NetConnection command extends basic connectivity testing with additional diagnostic capabilities. This versatile command can test specific TCP ports, display detailed routing information, and perform traceroute operations—all within a single command structure. When you need to verify whether a specific service is accessible, Test-NetConnection becomes invaluable.

Test-NetConnection -ComputerName mail.company.com -Port 443

The output from Test-NetConnection includes the computer name, remote address, interface used for the connection, source address, whether ping succeeded, and—when testing a specific port—whether the TCP connection succeeded. This comprehensive information often reveals exactly where connectivity breaks down in complex network paths.

Domain Name System Resolution Diagnostics

Many connectivity problems that appear to be network issues actually stem from DNS resolution failures. When your computer cannot translate a hostname into an IP address, applications fail to connect even though the underlying network functions perfectly. PowerShell provides robust DNS diagnostic commands that quickly identify whether name resolution works correctly.

Resolving Hostnames to IP Addresses

The Resolve-DnsName command queries DNS servers to translate hostnames into IP addresses, revealing exactly what information your system receives when performing name lookups. This command shows all DNS records associated with a hostname, including IPv4 addresses (A records), IPv6 addresses (AAAA records), mail server information (MX records), and canonical names (CNAME records).

Resolve-DnsName -Name www.microsoft.com

When troubleshooting connectivity to a specific service, you might discover that DNS returns multiple IP addresses for load balancing purposes. Resolve-DnsName displays all returned addresses, which helps you understand whether connection failures occur with all addresses or only specific ones in the pool.

The -Type parameter allows you to query specific record types, which proves essential when troubleshooting email delivery, verifying domain ownership, or investigating more complex DNS configurations. Common record types include A (IPv4 address), AAAA (IPv6 address), MX (mail exchange), TXT (text records often used for verification), and NS (nameserver records).

Resolve-DnsName -Name company.com -Type MX

DNS Cache Management

Your computer maintains a local DNS cache that stores recently resolved names to improve performance. However, this cache can cause problems when DNS records change, as your system continues using outdated information. PowerShell provides commands to view and manage this cache when troubleshooting DNS-related issues.

The Get-DnsClientCache command displays all entries currently stored in your local DNS cache, showing the hostname, record type, status, and remaining time-to-live for each entry. Examining the cache often reveals whether your system has stored incorrect DNS information that prevents proper connectivity.

Get-DnsClientCache | Where-Object {$_.Entry -like "*company*"}

When you need to force your system to retrieve fresh DNS information, the Clear-DnsClientCache command removes all cached entries. After clearing the cache, subsequent name lookups query DNS servers directly, ensuring you receive current information rather than potentially outdated cached data.

Clear-DnsClientCache

"Half of all 'network problems' are actually DNS problems in disguise. Learn to verify name resolution first, and you'll solve issues twice as fast."

Network Configuration Analysis

Understanding your current network configuration forms the foundation for effective troubleshooting. PowerShell commands reveal how your network adapters are configured, what IP addresses they're using, which DNS servers they query, and how routing decisions are made. This information often points directly to configuration issues that cause connectivity problems.

Examining Network Adapter Configuration

The Get-NetIPConfiguration command provides a comprehensive overview of network adapter settings, displaying interface names, IP addresses, subnet masks, default gateways, and DNS servers. This command serves as your starting point when investigating network configuration issues, giving you a complete picture of how your system connects to networks.

Get-NetIPConfiguration -Detailed

For more granular information about specific aspects of network configuration, PowerShell offers specialized commands. Get-NetIPAddress focuses specifically on IP address assignments, showing both IPv4 and IPv6 addresses along with their prefix lengths and address states. This command helps identify IP address conflicts, incorrect subnet configurations, or unexpected address assignments.

Get-NetIPAddress -AddressFamily IPv4 | Format-Table InterfaceAlias, IPAddress, PrefixLength

The Get-NetAdapter command reveals physical and virtual network adapters present on your system, displaying their status, link speed, and MAC addresses. When troubleshooting connectivity issues, verifying that adapters are enabled and showing the expected link speed often identifies hardware or driver problems.

Command Primary Use Key Information Provided
Get-NetIPConfiguration Overall network settings overview IP addresses, gateways, DNS servers, interface status
Get-NetIPAddress Detailed IP address information Address assignments, prefix lengths, address families
Get-NetAdapter Network adapter status Adapter names, status, link speed, MAC addresses
Get-DnsClientServerAddress DNS server configuration DNS servers assigned to each adapter
Get-NetRoute Routing table examination Network destinations, gateways, metrics, interface assignments

DNS Server Configuration

Incorrect DNS server configuration causes widespread connectivity problems, particularly when accessing resources by hostname. The Get-DnsClientServerAddress command shows which DNS servers each network adapter uses, helping you verify that appropriate DNS servers are configured for your network environment.

Get-DnsClientServerAddress -AddressFamily IPv4

When you need to change DNS server assignments, PowerShell provides the Set-DnsClientServerAddress command. This capability proves valuable when testing whether connectivity issues relate to DNS server problems—you can temporarily switch to alternative DNS servers like Google's 8.8.8.8 or Cloudflare's 1.1.1.1 to determine whether name resolution improves.

Port Connectivity and Service Testing

Modern applications communicate through specific network ports, and connectivity problems often occur because firewalls block required ports or services aren't listening where expected. PowerShell commands can test whether specific ports accept connections, helping you distinguish between general network problems and service-specific issues.

Testing Specific Port Availability

The Test-NetConnection command with the -Port parameter attempts to establish a TCP connection to a specific port on a remote system. This test tells you whether a service is accessible at the network level, regardless of whether the application itself functions correctly. Common ports to test include 80 (HTTP), 443 (HTTPS), 3389 (Remote Desktop), 445 (SMB file sharing), and 1433 (SQL Server).

Test-NetConnection -ComputerName server.company.com -Port 3389

The output includes a TcpTestSucceeded property that clearly indicates whether the connection attempt succeeded. When this value shows False, either a firewall blocks the port, the service isn't running, or the service listens on a different port than expected. This information dramatically narrows your troubleshooting focus.

"When users say 'the network is down,' what they usually mean is 'I can't access this specific thing.' Testing specific ports helps you understand what's actually broken rather than chasing phantom network problems."

Identifying Local Port Listeners

Understanding which services listen on your local system helps troubleshoot why connections fail or succeed. The Get-NetTCPConnection command displays all TCP connections and listening ports on your computer, showing local addresses, remote addresses, connection states, and the process IDs responsible for each connection.

Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess | Sort-Object LocalPort

By combining this command with Get-Process, you can identify exactly which application listens on each port. This information proves invaluable when investigating port conflicts or verifying that services start correctly and bind to expected ports.

Get-NetTCPConnection -LocalPort 80 | Select-Object -Property State, OwningProcess, @{Name="ProcessName";Expression={(Get-Process -Id $_.OwningProcess).ProcessName}}

Route Tracing and Path Analysis

Network packets travel through multiple routers between source and destination systems. When connectivity fails or performs poorly, understanding the path packets take helps identify where problems occur. PowerShell provides commands that trace network routes and analyze the path between systems.

Tracing Network Paths

The Test-NetConnection command with the -TraceRoute parameter performs a traceroute operation, showing each router hop between your computer and the destination. This information reveals where packets successfully travel and where they fail to proceed further, pinpointing the network segment where problems exist.

Test-NetConnection -ComputerName remote-server.com -TraceRoute

Each hop in the trace route output shows the router's IP address and the time required to reach that point. When you see timeouts or significantly increased latency at a specific hop, you've identified where network performance degrades or connectivity fails. This information proves essential when working with network teams to resolve infrastructure issues.

Examining the Routing Table

Your computer maintains a routing table that determines which network interface and gateway to use when sending packets to different destinations. The Get-NetRoute command displays this routing table, showing how your system makes routing decisions for various network destinations.

Get-NetRoute -AddressFamily IPv4 | Format-Table DestinationPrefix, NextHop, RouteMetric, InterfaceAlias

Incorrect routing table entries can cause packets to use wrong interfaces or gateways, leading to connectivity failures that seem mysterious until you examine routing decisions. The routing table shows destination prefixes (network ranges), next hop addresses (gateways), route metrics (priority values), and interface assignments.

Scenario Recommended Command What to Look For
Website won't load Test-NetConnection -ComputerName domain.com -Port 443 TcpTestSucceeded value and PingSucceeded value
Cannot access file share Test-NetConnection -ComputerName fileserver -Port 445 Whether SMB port responds successfully
Email client won't connect Resolve-DnsName -Name mail.server.com -Type MX Correct mail server addresses and priorities
Intermittent connectivity Test-Connection -ComputerName gateway -Continuous Patterns in packet loss or latency spikes
Remote desktop fails Test-NetConnection -ComputerName remotepc -Port 3389 RDP port accessibility and firewall status

Network Statistics and Performance Analysis

Beyond basic connectivity testing, PowerShell provides commands that reveal network performance statistics, error rates, and traffic patterns. This information helps diagnose performance problems and identify network adapter or infrastructure issues that impact reliability.

Viewing Network Adapter Statistics

The Get-NetAdapterStatistics command displays traffic statistics for network adapters, including bytes sent and received, packets transmitted, and error counts. Monitoring these statistics over time helps identify whether network performance problems relate to your local adapter or external network conditions.

Get-NetAdapterStatistics | Format-Table Name, ReceivedBytes, SentBytes, ReceivedUnicastPackets, SentUnicastPackets

Significant error counts or discarded packet counts indicate hardware problems, driver issues, or network congestion. Comparing statistics before and after connectivity problems helps correlate issues with specific traffic patterns or system behaviors.

TCP Connection Statistics

The Get-NetTCPConnection command not only shows active connections but also provides insights into connection states. Understanding how many connections exist in various states helps diagnose application issues, identify port exhaustion problems, and recognize unusual traffic patterns that might indicate security issues.

Get-NetTCPConnection | Group-Object -Property State | Select-Object Name, Count

Large numbers of connections in TIME_WAIT state might indicate application connection handling issues, while many connections in SYN_SENT state suggest connection establishment failures. These patterns provide diagnostic clues that guide further investigation.

"Network statistics tell stories that simple connectivity tests miss. Learning to read these patterns transforms you from someone who fixes obvious problems to someone who prevents problems before users notice them."

Firewall and Security Configuration

Windows Firewall often blocks network traffic that causes connectivity problems, yet administrators sometimes overlook firewall rules when troubleshooting. PowerShell provides comprehensive commands for examining and managing firewall configurations, helping you identify whether security policies prevent legitimate traffic.

Examining Firewall Rules

The Get-NetFirewallRule command displays Windows Firewall rules, showing which traffic the firewall allows or blocks. With potentially hundreds of rules configured, filtering this output to find relevant rules requires understanding the command's parameters and PowerShell's filtering capabilities.

Get-NetFirewallRule -Enabled True -Direction Inbound | Where-Object {$_.Action -eq 'Block'} | Format-Table DisplayName, Profile, Action

When troubleshooting connectivity to a specific port, you can search for rules affecting that port using the Get-NetFirewallPortFilter command combined with Get-NetFirewallRule. This approach quickly reveals whether firewall rules block the traffic you're attempting to send or receive.

Get-NetFirewallPortFilter | Where-Object {$_.LocalPort -eq 80} | Get-NetFirewallRule | Format-Table DisplayName, Enabled, Action, Direction

Testing with Firewall Temporarily Disabled

When you suspect firewall rules cause connectivity problems but can't identify the specific rule, temporarily disabling the firewall helps confirm whether security policies block traffic. The Set-NetFirewallProfile command allows you to disable the firewall for testing purposes, though this should only be done briefly and in controlled situations.

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False

If connectivity works with the firewall disabled, you've confirmed that firewall rules cause the problem. You can then re-enable the firewall and systematically review rules to identify which specific rule blocks legitimate traffic. Remember to re-enable the firewall immediately after testing.

Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True

Advanced Troubleshooting Techniques

Experienced administrators combine multiple PowerShell commands into scripts that perform comprehensive network diagnostics automatically. These approaches save time when troubleshooting recurring issues and provide consistent documentation of network conditions.

Creating Diagnostic Scripts

Building a PowerShell script that executes multiple diagnostic commands in sequence creates a comprehensive network health check. Such scripts might test connectivity to multiple critical servers, verify DNS resolution for important hostnames, check firewall status, and document current network configuration—all with a single command execution.

$results = @()
$results += Test-Connection -ComputerName gateway -Count 2 -Quiet
$results += Test-NetConnection -ComputerName dns-server -Port 53
$results += Resolve-DnsName -Name critical-app.company.com
$results | Format-List

Scripts can also implement logic that performs different tests based on initial results. For example, if basic connectivity fails, the script might examine local network configuration and firewall rules. If connectivity succeeds but name resolution fails, the script might focus on DNS configuration and cache contents.

Remote Network Troubleshooting

PowerShell's remoting capabilities allow you to execute network diagnostic commands on remote computers, enabling centralized troubleshooting of distributed systems. The Invoke-Command cmdlet runs commands on remote systems, returning results to your local console.

Invoke-Command -ComputerName remote-server -ScriptBlock {Test-NetConnection -ComputerName database-server -Port 1433}

This approach proves invaluable when troubleshooting connectivity between systems you don't physically access. Rather than asking remote users to run commands and interpret results, you can execute diagnostic commands remotely and analyze output directly.

"The most powerful troubleshooting tool isn't any single command—it's the ability to chain commands together logically, letting each result guide your next diagnostic step."

Network Adapter Management and Reset Procedures

Sometimes network connectivity problems stem from network adapter states that require reset procedures to resolve. PowerShell provides commands to disable and re-enable adapters, reset TCP/IP stacks, and flush various network caches—operations that often resolve stubborn connectivity issues.

Restarting Network Adapters

The Restart-NetAdapter command disables and re-enables a network adapter, forcing it to release and renew its network configuration. This operation often resolves issues caused by adapter state problems or temporary configuration glitches.

Restart-NetAdapter -Name "Ethernet"

You can also use separate Disable-NetAdapter and Enable-NetAdapter commands when you need more control over the timing of the restart process. This approach allows you to perform other operations while the adapter is disabled or wait for specific conditions before re-enabling connectivity.

Resetting TCP/IP Configuration

When network configuration becomes corrupted, resetting the TCP/IP stack to default settings can resolve persistent connectivity problems. PowerShell provides access to netsh commands through the Start-Process cmdlet or direct command execution, allowing you to reset network configurations when necessary.

netsh int ip reset
netsh winsock reset

These reset operations require administrator privileges and typically require system restart to take full effect. They should be considered when standard troubleshooting steps fail to resolve connectivity issues and you suspect fundamental configuration corruption.

Practical Troubleshooting Workflows

Effective network troubleshooting follows systematic approaches rather than random command execution. Understanding how to structure your diagnostic process ensures you identify problems efficiently and avoid overlooking critical information.

The Layer-by-Layer Approach

Professional troubleshooting typically proceeds through network layers systematically. Start by verifying physical connectivity and basic network configuration, then test network layer connectivity, verify name resolution, and finally test application-specific connectivity. This approach ensures you don't waste time investigating application issues when the underlying network doesn't function.

✨ Verify network adapter status and configuration with Get-NetAdapter and Get-NetIPConfiguration

✨ Test basic connectivity to your default gateway using Test-Connection

✨ Verify internet connectivity by testing connection to well-known public servers

✨ Test DNS resolution with Resolve-DnsName for critical hostnames

✨ Verify specific service connectivity using Test-NetConnection with appropriate ports

Documentation and Baseline Comparison

Capturing network configuration and performance information when systems work correctly creates baselines for comparison during troubleshooting. PowerShell's ability to export command results to files enables systematic documentation that proves invaluable when diagnosing intermittent or complex issues.

Get-NetIPConfiguration -Detailed | Out-File -FilePath C:\NetworkBaseline.txt
Get-NetRoute | Export-Csv -Path C:\RoutingTable.csv -NoTypeInformation

When problems occur, you can compare current configuration against these baselines to identify what changed. This approach quickly reveals configuration modifications that caused connectivity problems, even when those changes weren't intentional or documented.

"Troubleshooting without a systematic approach is just guessing with extra steps. Following a consistent diagnostic process turns mysterious problems into logical puzzles with clear solutions."
How do I test if a specific website is accessible from my computer?

Use the Test-NetConnection command with the website's hostname and port 443 for HTTPS sites or port 80 for HTTP sites. For example: Test-NetConnection -ComputerName www.example.com -Port 443. The TcpTestSucceeded property in the output indicates whether the connection succeeded. If the connection fails, try testing basic connectivity with Test-Connection to determine whether the issue is general network connectivity or specific to the web service.

What's the difference between Test-Connection and Test-NetConnection?

Test-Connection is PowerShell's equivalent to the ping command, sending ICMP echo requests to test basic network reachability. Test-NetConnection provides more comprehensive diagnostics, including the ability to test specific TCP ports, perform traceroute operations, and display detailed routing information. For basic connectivity testing, Test-Connection suffices, but Test-NetConnection offers greater diagnostic capabilities when troubleshooting specific services or investigating complex connectivity issues.

How can I determine which DNS servers my computer is using?

The Get-DnsClientServerAddress command displays DNS server configurations for all network adapters. Add the -AddressFamily IPv4 parameter to focus on IPv4 DNS servers specifically. This command shows which DNS servers each adapter queries for name resolution. If you suspect DNS problems, verify that these servers are accessible using Test-Connection and that they return correct information using Resolve-DnsName.

Why does Test-Connection work but I still cannot access a service?

Test-Connection only verifies that ICMP echo requests reach the destination and return responses, confirming basic network connectivity. However, services operate on specific TCP or UDP ports that might be blocked by firewalls even when ICMP traffic passes through. Use Test-NetConnection with the -Port parameter to test connectivity to the specific port the service uses. If port testing fails while ping succeeds, firewall rules likely block the service traffic.

How do I troubleshoot DNS problems when websites won't load?

Start by using Resolve-DnsName to verify that DNS queries return correct IP addresses for the hostnames you're trying to access. If resolution fails or returns incorrect addresses, check your DNS server configuration with Get-DnsClientServerAddress. Clear your DNS cache using Clear-DnsClientCache to ensure you're not using stale information. Test whether alternative DNS servers resolve names correctly by temporarily changing DNS settings with Set-DnsClientServerAddress. If external DNS servers work but your configured servers don't, the problem lies with your DNS infrastructure rather than your local configuration.

What should I do when network commands require administrator privileges?

Many network configuration commands require administrator privileges to execute. Right-click the PowerShell icon and select "Run as Administrator" to launch an elevated PowerShell session. Commands that only read information typically don't require elevation, but commands that modify configuration, manage firewall rules, or reset network settings require administrator rights. If you regularly perform network troubleshooting, consider creating a PowerShell profile that includes frequently-used diagnostic commands to streamline your workflow.