How to check open ports with PowerShell

[How in German Language] How to include a batch script in Windows task scheduling? service that is accessed on the network needs a port. Behind this port is the protocol which is used. For example, port 80 would be responsible for opening web pages. How can you test ports with PowerShell?

Ports are, of course, the key to accessing a system. That’s why you should always have only those ports open that are absolutely necessary. So how can you check which ports are open?

There are optimal programs like nmap, which is highly recommended for an extensive and detailed analysis. Of course, there are other Windows on-board tools, such as netstat.

However, if you only want to test briefly whether a certain port is open on the server, this can easily be done with Windows PowerShell?

Test-NetConnection -Port 22

The Test-NetConnection cmdlet now checks port 22 at the following IP address, which is SSH access. The output returns the result TcpTestSucceeded : True. This means that this port is open.

Since this is TCP (Transmission Control Protocol), you should also know its basic operation. When TCP sends a packet, a so called SYN is sent. The remote computer answers with SYN + ACK.

This means the port is open. However, if it sends a RST as an answer, no connection would be possible. Of course, the answer to TcpTestSucceeded would be False.

Test-NetConnection -Port 80

In this example, port 80 was tested, which is responsible for the HTTP protocol. As the following screenshot shows, this port is not open on the system with IPv4 address

Mit der Windows PowerShell einen Port prüfen - TestNetConnection - Port geschlossen
How to check open ports with PowerShell

For a quick test whether a certain port is open on the server, Windows PowerShell is quite sufficient. By the way, you can read more details about ports in the article: How to understand what is meant by ports in 3 minutes in networking.

If you would like to learn more about Windows PowerShell, there are excellent courses from Udemy. Often these are also on offer. It might be worth a look: The following is recommended:

Einstieg in die Windows PowerShell Cookbook – Udemy Kurs*

Dieser Artikel beinhaltet Partner-Links. Durch einen Klick darauf ge­lan­gt ihr direkt zum Anbieter. Solltet ihr euch dort für einen Kauf entscheiden, erhält IT-Learner eine kleine Provision. Der Preis ändert sich für euch nicht. Danke für eure Unterstützung! Letzte Aktualisierung am 17.02.2024

Der Blogbetreiber und Autor: Markus Elsberger

Über den Autor

Mein Name ist Markus Elsberger und ich beschäftige mich mit der Administration von Windows und Linux Systemen sowie mit diversen Themen bzgl. Netzwerktechnik. In meiner Lehrtätigkeit erstelle ich verschiedene Szenarien und teste auch verschiedene Konfigurationen, welche ich in diesem Blog festhalten möchte.

Kostenlose Befehlsreferenzen und E-Books
(Netzwerkanalyse, Benutzerverwaltung, Festplattenkonfiguration, u. v. m.)

Nach oben scrollen