Hey there! Today I’m going to show you how to check if a port is open using PowerShell. This is one of those tasks that sounds technical, but it’s actually pretty straightforward once you know the right PowerShell commands.
Whether you’re troubleshooting a network issue, setting up a new server, or just trying to figure out why an application won’t connect, knowing how to check port status is super useful.
Let me walk you through everything you need to know.
Why Would You Want to Check if a Port is Open?
Before we jump into the how-to part, let’s talk about why this matters.
Ports are like doors on your computer or server. Different applications use different ports to communicate over the network. For example, web servers typically use port 80 for HTTP and port 443 for HTTPS. Email servers use port 25, and so on.
Sometimes you need to verify that:
- A specific service is running and listening on the expected port
- Your firewall isn’t blocking a port you need
- A remote server is accessible on a particular port
- There’s no conflict with another application using the same port
Knowing how to check this can save you hours of troubleshooting headaches.
Check out: Why Does Windows PowerShell Keep Popping Up?
The Test-NetConnection Command (The Modern Way)
The easiest and most modern way to check if a port is open in PowerShell is using the Test-NetConnection command. This command is available in Windows 8.1, Windows Server 2012 R2, and later versions.
Here’s the basic syntax:
Test-NetConnection -ComputerName hostname -Port portnumberLet me show you a real example. Let’s say you want to check if Google’s web server is accessible on port 443:
Test-NetConnection -ComputerName google.com -Port 443When you run this command, PowerShell will give you a detailed output that looks something like this:
ComputerName : google.com
RemoteAddress : 142.251.223.14
RemotePort : 443
InterfaceAlias : Wifi
SourceAddress : 192.168.68.105
TcpTestSucceeded : TrueThe key thing to look at here is TcpTestSucceeded. If it says True, the port is open and accepting connections. If it says False, the port is either closed or being blocked.
Here is the exact output in the screenshot below:

Pretty simple, right?
Making It Shorter with Parameters
You can also use the shortened parameter names to make your command quicker to type:
Test-NetConnection google.com -Port 443Or even shorter using aliases:
tnc google.com -Port 443Both of these do exactly the same thing as the longer version.
Checking Your Local Machine
You can also check ports on your own computer using localhost or 127.0.0.1:
Test-NetConnection -ComputerName localhost -Port 3306This is super helpful when you’re running services locally and want to verify they’re listening on the right port.
Check out PowerShell Get-WindowsAutoPilotInfo
Getting Just a True/False Answer
Sometimes you don’t need all that detailed information. You just want a simple yes or no answer. Here is the PowerShell script to check if a Port is Open.
You can grab just the TcpTestSucceeded property like this:
(Test-NetConnection -ComputerName google.com -Port 443).TcpTestSucceededThis will return either True or False. Nothing else.
Here is the exact output in the screenshot below:

This is particularly useful when you’re writing scripts and need to make decisions based on whether a port is open.
Read How to Check Who Modified a File Last in Windows Using PowerShell
The Old-School Method: Using .NET Classes
If you’re working with older versions of Windows that don’t have Test-NetConnection, don’t worry. You can use .NET classes directly in PowerShell.
Here’s how:
$tcpClient = New-Object System.Net.Sockets.TcpClient
try {
$tcpClient.Connect("google.com", 443)
Write-Host "Port 443 is open" -ForegroundColor Green
$tcpClient.Close()
} catch {
Write-Host "Port 443 is closed or unreachable" -ForegroundColor Red
}This creates a TCP client object and tries to connect to the specified host and port. If it succeeds, the port is open. If it throws an error, the port is closed or blocked.
Read Delete User Profiles Using PowerShell in Windows 11
Checking Multiple Ports at Once
Now here’s where PowerShell really shines. You can easily check multiple ports at once using a loop.
Let’s say you want to check if ports 80, 443, and 8080 are open on a server:
$ports = 80, 443, 8080
foreach ($port in $ports) {
$result = Test-NetConnection -ComputerName example.com -Port $port -WarningAction SilentlyContinue
if ($result.TcpTestSucceeded) {
Write-Host "Port $port is OPEN" -ForegroundColor Green
} else {
Write-Host "Port $port is CLOSED" -ForegroundColor Red
}
}The -WarningAction SilentlyContinue parameter suppresses any warning messages, making your output cleaner.
Checking Ports on Multiple Servers
You can take this even further and check the same port on multiple servers using the following PowerShell script:
$servers = "server1.domain.com", "server2.domain.com", "server3.domain.com"
$port = 443
foreach ($server in $servers) {
$result = Test-NetConnection -ComputerName $server -Port $port -WarningAction SilentlyContinue
Write-Host "$server - Port $port : $($result.TcpTestSucceeded)"
}This is incredibly useful when you’re managing multiple servers and need to verify they’re all accessible.
Create a Reusable Function in PowerShell
If you find yourself checking ports frequently, you might want to create a function in PowerShell. Here’s a nice one you can add to your PowerShell profile:
function Test-Port {
param(
[Parameter(Mandatory=$true)]
[string]$ComputerName,
[Parameter(Mandatory=$true)]
[int]$Port
)
$result = Test-NetConnection -ComputerName $ComputerName -Port $Port -WarningAction SilentlyContinue
if ($result.TcpTestSucceeded) {
Write-Host "✓ $ComputerName : Port $Port is OPEN" -ForegroundColor Green
return $true
} else {
Write-Host "✗ $ComputerName : Port $Port is CLOSED" -ForegroundColor Red
return $false
}
}Now you can simply use:
Test-Port -ComputerName google.com -Port 443Much cleaner and easier to remember!
Check out Track User Login History on Windows Using PowerShell
Common Ports You Might Want to Check
Here are some commonly used ports you might find yourself checking:
- Port 80 – HTTP (web traffic)
- Port 443 – HTTPS (secure web traffic)
- Port 22 – SSH (secure shell)
- Port 21 – FTP (file transfer)
- Port 25 – SMTP (email)
- Port 3306 – MySQL database
- Port 1433 – SQL Server
- Port 3389 – Remote Desktop Protocol (RDP)
- Port 8080 – Alternative HTTP port
Troubleshooting Tips
If a port shows as closed when you expect it to be open, here are some things to check:
First, make sure the service is actually running. A port won’t be open if nothing is listening on it.
Second, check your firewall settings. Both the local Windows Firewall and any network firewalls could be blocking the connection.
Third, verify you’re using the correct hostname or IP address. Typos happen!
Fourth, make sure the server itself is reachable. Try pinging it first to verify basic network connectivity.
Wrapping Up
Checking if a port is open in PowerShell is really straightforward once you know the right commands. The Test-NetConnection cmdlet is your best friend for modern Windows systems, while the .NET method works great for older versions.
Remember these key points:
- Use
Test-NetConnection -ComputerName hostname -Port portnumberfor a quick check - Look for
TcpTestSucceeded : Truein the output - You can check multiple ports or servers using loops
- Create functions for tasks you do repeatedly
Now you’ve got all the tools you need to diagnose port connectivity issues like a pro. Go ahead and give these commands a try – you’ll be surprised how often they come in handy!
You may also like the following tutorials:
- Set the Default Printer Using PowerShell in Windows
- Set the Time Zone Using PowerShell in Windows
- Set Password for Local User in Windows 11 Using PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.