anthonyg-1 / PSTcpIp

This PowerShell module contains functions that faciliate testing network connectivity, TLS/SSL and other network tasks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add 5986 to port list

jdhitsolutions opened this issue · comments

I suggest adding port 5986 to your port list for WSMan SSL connections. Another option would be to add commands to the module to let the user manage $tcpPortAndDescriptionData. I know I can do something like this:

$tcpPortAndDescriptionData[5986] = "WinRM/SSL"

But it is always nicer to give the user a command.

Hi Jeff, I added port 5986 to the list. I'm not quite sure about adding a function to have the user manage the port list though. Can you elaborate as to what that may look like? Right now the user cannot add ports to the JSON file, but they can pass an array of ports to the Port parameter.

I threw together some rough functions of what I had in mind.

Function Set-TCPPortDescription {
    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(Position = 0, Mandatory)]
        [int32]$Port,
        [Parameter(Position = 1, Mandatory)]
        [string]$Description,
        [switch]$PassThru
    )

    if ($PSCmdlet.ShouldProcess("$port/$description")) {
        $global:tcpPortAndDescriptionData[$port] = $Description
        if ($PassThru) {
            Get-TCPPortDescription -Port $port
        }
    }
}

Function Remove-TCPPortDescription {
    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(Position = 0, Mandatory)]
        [int32]$Port
    )

    if ($PSCmdlet.ShouldProcess($port)) {
        $global:tcpPortAndDescriptionData.Remove($port)
    }
}

Function Get-TCPPortDescription {
    [CmdletBinding(SupportsShouldProcess)]
    Param(
        [Parameter(Position = 0)]
        [int32]$Port
    )

    if ($Port -AND $global:tcpPortAndDescriptionData.ContainsKey($port)) {
        [PSCustomObject]@{Port = $Port;Description = $global:tcpPortAndDescriptionData[$port]}
    }
    elseif ($Port -AND (-Not $global:tcpPortAndDescriptionData.ContainsKey($port))) {
        Write-Warning "Port $port not defined."
    }
    else {
        $global:tcpPortAndDescriptionData.GetEnumerator() | ForEach-Object { [PSCustomObject]@{Port = $_.Key;Description = $_.Value}}
    }
}

The idea is that a user might have a custom port. I know they can specify it, but if it isn't in your list, I don't think they get a description.

image

The user could use these functions to manage the port list after it has been imported. Nobody has to touch the JSON file, but you give the user flexibility.