Skip to content

Test-NetConnection cmdlet is missing from PowerShell Core 6.0.1 release #6932

Closed

Description

Test-Connection was added in 5328 but it appears that Test-NetConnection is still missing.

Steps to reproduce

Get-Command Test-NetConnection

Expected behavior


CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Function        Test-NetConnection                                 1.0.0.0    NetTCPIP

Actual behavior

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

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0-preview.2
PSEdition                      Core
GitCommitId                    v6.1.0-preview.2
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. iSazonov commented on May 24, 2018

    @iSazonov
    Collaborator

    We added Test-Connection - this is new ported cmdlet. Test-NetConnection - this is Windows PowerShell cmdlet from nettcpip module.

  2. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on May 24, 2018
  3. cassie-nahar commented on May 24, 2018

    @cassie-nahar
    Author

    I'm a little unclear, does that mean that Powershell 6 will not have Test-NetConnection? I would expect the ability to check a specific port on a system would be of even more interest to unix admins.

    My assumption was that, like Test-Connection, Test-NetConnection had also been overlooked. If that was an incorrect assumption, then perhaps this should be re-labeled as a feature request. Otherwise, I believe this is a bug.

  4. iSazonov commented on May 25, 2018

    @iSazonov
    Collaborator

    @kevinlrak Current Test-Connection ported implementation was enhanced. Please see help Test-Connection.

    Get-Help -Name Test-Connection
    NAME
        Test-Connection
    
    SYNTAX
        Test-Connection [-TargetName] <string[]> [-Ping] [-IPv4] [-IPv6] [-ResolveDestination] [-Source <string>]
        [-MaxHops <int>] [-Count <int>] [-Delay <int>] [-BufferSize <int>] [-DontFragment] [-TimeoutSeconds <int>]
        [-Quiet] [<CommonParameters>]
    
        Test-Connection [-TargetName] <string[]> [-Ping] [-IPv4] [-IPv6] [-ResolveDestination] [-Source <string>]
        [-MaxHops <int>] [-Delay <int>] [-BufferSize <int>] [-DontFragment] [-Continues] [-TimeoutSeconds <int>] [-Quiet]
        [<CommonParameters>]
    
        Test-Connection [-TargetName] <string[]> -Traceroute [-IPv4] [-IPv6] [-ResolveDestination] [-Source <string>]
        [-MaxHops <int>] [-TimeoutSeconds <int>] [-Quiet] [<CommonParameters>]
    
        Test-Connection [-TargetName] <string[]> -MTUSizeDetect [-IPv4] [-IPv6] [-ResolveDestination] [-TimeoutSeconds
        <int>] [-Quiet] [<CommonParameters>]
    
        Test-Connection [-TargetName] <string[]> -TCPPort <int> [-IPv4] [-IPv6] [-ResolveDestination] [-Source <string>]
        [-TimeoutSeconds <int>] [-Quiet] [<CommonParameters>]

    You can to check a specific port too.
    .Net Core has still bugs in APIs and not all in Test-Connection works on Unix.
    Feel free to test and feedback.

    Nettcpip module is not in the repo (another MSFT team is owner) and it is not ported.

  5. cassie-nahar commented on May 25, 2018

    @cassie-nahar
    Author

    Ilya (@iSazonov) what version are you running? I'm on the 6.1.0-preview.2, but my help Test-Connection does not match what you put above. Neither does the online help page for Test-Connection in Powershell 6.

    Here is what I get:

    SYNTAX
        Test-Connection [-ComputerName] <String[]> [-AsJob] [-BufferSize <Int32>] [-Count <Int32>] [-Delay <Int32>] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-ThrottleLimit <Int32>] [-TimeToLive <Int32>] [-DcomAuthentication <AuthenticationLevel>] [-Protocol <String>] [-WsmanAuthentication <String>] [<CommonParameters>]
    
        Test-Connection [-ComputerName] <String[]> [-Source] <String[]> [-AsJob] [-BufferSize <Int32>] [-Count <Int32>] [-Credential <PSCredential>] [-Delay <Int32>] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-ThrottleLimit <Int32>] [-TimeToLive <Int32>] [-DcomAuthentication <AuthenticationLevel>] [-Protocol <String>] [-WsmanAuthentication <String>] [<CommonParameters>]
    
        Test-Connection [-ComputerName] <String[]> [-BufferSize <Int32>] [-Count <Int32>] [-Delay <Int32>] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-Quiet] [-TimeToLive <Int32>] [-DcomAuthentication <AuthenticationLevel>] [-Protocol <String>] [-WsmanAuthentication <String>] [<CommonParameters>]

    However, when I try running Test-Connection with the -TCPPort flag, it does seem to function. So I believe this is mostly a problem with that enhancement being undocumented in the latest current release (6.1.0-preview.2)

  6. iSazonov commented on May 25, 2018

    @iSazonov
    Collaborator

    @kevinlrak It is a trick :-) or bug. You catch Windows PowerShell help. You can find where it is by:

    gcm Test-Connection | fl

    I get

    DLL              : C:\Users\sie\Downloads\PowerShell-6.1.0-preview.9168-win-x64\Microsoft.PowerShell.Commands.M
                       anagement.dll
    HelpFile         : C:\Users\sie\Documents\PowerShell\Help\en-US\Microsoft.PowerShell.Commands.Management.dll-He
                       lp.xml
    

    After I rename folder C:\Users\sie\Documents\PowerShell\Help I get the right help.

  7. corretge commented on May 29, 2018

    @corretge

    In PowerShell 6.0.2, version installed through HomeBrew on a Mac, both commands are missing:

    • Get-Command : The term 'Test-NetConnection' is not recognized as the name of a cmdlet [...]
    • get-Command : The term 'Test-Connection' is not recognized as the name of a cmdlet [...]
    $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      6.0.2
    PSEdition                      Core
    GitCommitId                    v6.0.2
    OS                             Darwin 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEA...
    Platform                       Unix
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    
    
  8. iSazonov commented on May 29, 2018

    @iSazonov
    Collaborator

    Àlex Corretgé (@corretge) You'll get Test-Connection in 6.1 version or you can use 6.1 Preview2 or current dev builds.

  9. MrFly72 commented on Mar 13, 2022

    @MrFly72

    In my eyes this is breaking all compatibility with no understand from my side, why not implement Test-NetConnection...
    It would be really wise to implement it .
    This is again one of the commands where I have if/else for what it is running on. and worse enough, it has to be a check for 5.1/7.x, Windows/Linux (5.1 does not support -TCPPort, Linux does not support Test-NetConnection)
    is this the type of Multi-Plattform-Support Microsoft is aiming at?
    Please reconsider this, as it really breaks scripts that do network checks and should run on multiple plattforms or be easy to port.

  10. claytonolley commented on Apr 4, 2022

    @claytonolley

    I just came across this today and could really use Test-NetConnection in pwsh on Mac!

  11. vexx32 commented on Apr 4, 2022

    @vexx32
    Collaborator

    See above; you should be able to use Test-Connection for most of the use cases that Test-NetConnection covered in earlier versions. If you have a specific use case that the current implementation doesn't cover, I suggest you open a feature / improvement request for that cmdlet instead. 🙂

  12. MrFly72 commented on Apr 5, 2022

    @MrFly72

    Rain Sallow (/u/ta11ow) (@vexx32) But as said above. This breaks scripts to be compatible on multiple plattforms. And that because of a really bad reason, in my eyes, as Test-NetConnection could be easily built as the functionality is present in parts in test-connection.

  13. vexx32 commented on Apr 5, 2022

    @vexx32
    Collaborator

    I have to disagree, since I wrote quite a lot of the current implementation of Test-Connection. Many of the features Test-NetConnection had are simply not available in .NET itself currently. Even the things that are there largely only work on Windows, from what I've been able to determine.

    It's probably possible with a third-party library, but I'm not familiar enough in that area to know what would be useful to look at, nor would I expect the maintainers to want to pull it in as a permanent dependency.

    Test-NetConnection is simply not cross-platform compatible; some of the things it does on WIndows simply don't have direct analogues on other platforms, as far as I am able to tell. Test-Connection is, to the best of our current ability, the closest we have and is available even back in WinPS 5.1 (with some minor differences from the current implementation; it too had to be rewritten completely, in the end).

    If you'd like to expand what it can do, feel free; I have no doubt that useful functionality would likely be welcomed as a PR. 🙂

  14. MrFly72 commented on Apr 5, 2022

    @MrFly72

    But exactly thats the current problem. Test-Connection does not support eg. TCPPort in 5.1
    So there is no way currently to write code that can be used on 5.1 + 7.x on multiple plattforms, other then doing stuff like.
    if ($IsLinux) ..... etc. In my script I am doing this:

    if ($IsLinux) {
        if (-Not (Test-Connection -TargetName $url -TcpPort $port)) {
            Write-Host "Warning! Synology cannot be reached!!!" -ForegroundColor Red
        }
    }
    else {
        if (-Not (Test-NetConnection -ComputerName $url -Port $port)) {
            Write-Host "Warning! Synology cannot be reached!!!" -ForegroundColor Red
        }
    }
    
  15. vexx32 commented on Apr 5, 2022

    @vexx32
    Collaborator

    I mean, if you ensure you're using the same version of PowerShell on both, you can skip the check. Beyond that, I don't know what you can really expect, they're two different software packages.

  16. ClaytonOlleyNutrien commented on Apr 5, 2022

    @ClaytonOlleyNutrien

    Test-Connection is icmp only... I specifically needed something to test a tcp port connection. I just ended up using netcat instead.

  17. MrFly72 commented on Apr 5, 2022

    @MrFly72

    Test-Connection is icmp only... I specifically needed something to test a tcp port connection. I just ended up using netcat instead.

    With -TCPPort Parameter it is a TCP-Connection?

  18. ClaytonOlleyNutrien commented on Apr 5, 2022

    @ClaytonOlleyNutrien

    My apologies, I missed that. The documentation could use some updating it seems. Thanks, and sorry to bother!

  19. shaheerxt commented on Oct 27, 2022

    @shaheerxt

    I know this discussion has been closed, but I wanted to provide an important takeaway.

    I am using mac and installed powershell for it.
    brew install --cask powershell

    I access it using pwsh command.

    First i logged in with Az login , and it was successful.

    But i faced an issue with Get-AzStorageAccount command.
    Get-AzStorageAccount: The term 'Get-AzStorageAccount' is not recognized as a name of a cmdlet, function, script file, or executable program.

    So installed Az module
    Install-Module Az

    But still there was an issue with port connectivity check

    PS /Users/whosecode> Test-NetConnection -ComputerName ([System.Uri]::new($storageAccount.Context.FileEndPoint).Host) -Port 445
    Test-NetConnection: The term 'Test-NetConnection' is not recognized as a name of a cmdlet, function, script file, or executable program.
    

    So I came across a note about Test-Connection instead of Test-NetConnection , and it seems returning right result.

    PS /Users/whosecode> Test-Connection -ComputerName ([System.Uri]::new($storageAccount.Context.FileEndPoint).Host) -TcpPort 445
    False
    
  20. ahaleiii commented on Nov 30, 2022

    @ahaleiii

    Test-NetConnection has a SourceAddress property on the response, from which I can get the source IPAddress.

    Test-Connection has a Source property on the response, but this only appears to be the hostname.

    Is there a way to replicate the Test-NetConnection behavior to get SourceAddress on Linux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions