How to work with the Test-NetConnection command in PowerShell. In the continuation of PowerShell tutorials, in this article, we are going to teach you how to work with the Test-NetConnection command in PowerShell.
In the previous article, which we taught how to set up a network through PowerShell, you got acquainted with some commands for setting up an IP address, and so on. In this article, we will explain a command that you can use to test the network. You are probably familiar with commands such as Ping, tracert or NetStat and have seen the use of each of them in CMD or other operating systems.
In PowerShell, CMD commands can be used. PowerShell, like its other commands, provides a specific command for working with the network, which is similar to the function of CMD commands, but sometimes provides more complete information.
Read on to learn how to work with the Test-NetConnection command in PowerShell.
Table of Contents
Working with the Test-NetConnection command in PowerShell
PowerShell commands are the same as CMD commands, but with a different functionality that you will see below.
Test-NetConnection command
The Test-NetConnection command is a combination of several frequently used network commands in CMD and has several parameters. The general structure of this command is the same as other PowerShell commands, and you can enter the desired parameter or values after entering the command.
See the following examples to learn more about this command.
Example for the Test-NetConnection command
You can use the following command to ping an IP address in PowerShell.
Test-NetConnection 192.18.1.1
Following command is used to ping based on a computer name or a domain.
Test-NetConnection –ComaputerName google.com
The PowerShell structure feature will allow you to enter a range of IPs so that PowerShell can ping them all.
1..99 | % { Test-NetConnection -ComputerName 192.168.1.$_ } | FT –AutoSize
In the above command, the value of 1..99 is the last number of the IP address and x.x.x is the network address where you can enter your desired values. PowerShell will ping all IP addresses in the range 192.168.1.1 to 192.168.1.99, respectively.
This feature is the simplest feature of the Test-NetConnection command. In the following, we will explain the other parameters of this command.
TraceRoute parameter
One of the widely used command in the Tracert network is PowerShell, which has become a parameter for the Test-NetConnection command. To use tracert, you can proceed as follows. The following command will work exactly the same as the Tracert command.
Test-NetConnection www.google.com –Traceroute
State parameter
Another command that exists in CMD and is used as a parameter in PowerShell is the Netstat command, which is executed in PowerShell via state and restores all established connections
Test-NetConnection –State Established
Port parameter
You will be able to use this parameter to check a specific port on a computer.
Test-NetConection –ComputerName google.com –Port 80
This command will check the status of port 80 on the Google.com server and finally provide information about the port in question.
By this command, you will also be able to use the CommonTCPPort parameter to scan all ports on a particular service.
For example, in the following command, we want the HTTP port to search for the 192.168.1.10 server.
Test-NetConnection 192.168.1.10 –CommonTCPPort http
After entering the above command, PowerShell starts scanning all the ports of the mentioned system. Whenever it can find the port on which the HTTP service is located, it will output to you.
You can use the Test-Netonnection command and its other application parameters and no longer use add-ons for this.
Use the following command in PowerShell for information on other parameters and other examples of the Test-NetConnection command:
Get-Help Test-NetConnection –detailed
Dear user, we hope you would enjoy this tutorial, you can ask questions about this training in the comments section, or to solve other problems in the field of Eldernode training, refer to the Ask page section and raise your problem in it as soon as possible. Make time for other users and experts to answer your questions.
Goodluck.