Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell cmdlet Test-NetConnection not available

I noticed that the cmdlet Test-NetConnection was not installed on Server 2012. Since Server 2012 comes with PowerShell version 3 so I thought it might help to update to the latest version 5.1.

I did the update but the cmdlet Test-NetConnection is still not available.

Only Test-Connection is present, but I need Test-NetConnection to test ports.

How can I get Test-NetConnection now?

PS C:\Windows\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1005
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1005
CLRVersion                     4.0.30319.34209
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\Windows\system32> Get-Command Test-NetConnection
Get-Command : The term 'Test-NetConnection' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-Command Test-NetConnection
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Test-NetConnection:String) [Get-Command], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand
like image 609
Paul Smith Avatar asked Nov 30 '17 10:11

Paul Smith


People also ask

How do I test PowerShell NetConnection?

PowerShell Test-Connection Just like ping, uses Test-Connection also the ICMP protocol to test the network connectivity of a network device. In the simplest form, you can type Test-Connection <computername> or <ip-address> to do a quick connectivity test.

How do you use the test NetConnection command?

If you set this parameter to Quiet, the cmdlet returns basic information. For example, for a ping test, this cmdlet returns a Boolean value that indicates whether the attempt to ping a host or port is successful. Specifies the TCP port number on the remote computer.

How do I test TCP connection in Windows 10?

Press the Windows key + R, then type "cmd.exe" and click OK. Enter "telnet + IP address or hostname + port number" (e.g., telnet www.example.com 1723 or telnet 10.17. xxx. xxx 5000) to run the telnet command in Command Prompt and test the TCP port status.


2 Answers

The availability of many cmdlets is tied to the Windows version, not the PowerShell version. If you can't upgrade your Windows version you can't have Test-NetConnection.

You could use a commandline port scanner like nmap or scanline for port tests, or you could connect to the port(s) yourself:

function Test-Port($server, $port) {
    $client = New-Object Net.Sockets.TcpClient
    try {
        $client.Connect($server, $port)
        $true
    } catch {
        $false
    } finally {
        $client.Dispose()
    }
}
like image 54
Ansgar Wiechers Avatar answered Oct 16 '22 09:10

Ansgar Wiechers


$ipaddress = "serverName"
$port = "portNum"
$connection = New-Object System.Net.Sockets.TcpClient($ipaddress, $port)
if ($connection.Connected) {
     Write-Host "Success" 
} else { 
     Write-Host "Failed" 
}
like image 30
Roger Perkins Avatar answered Oct 16 '22 08:10

Roger Perkins