New-RDMPort

    2025-02-17

    New-RDMPort

    SYNOPSIS

    Generate port number(s) based on the specified parameters.

    SYNTAX

    __AllParameterSets

    New-RDMPort [-Count <int>] [-ExcludePort <int[]>] [-IncludeWellKnownPorts] [-IncludeRegisteredPorts]
     [-IncludePortsUsedByOthersSessions] [-Maximum <int>] [-Minimum <int>]
     [-ForcePromptAnswer <DialogResult[]>] [<CommonParameters>]
    

    ALIASES

    This cmdlet has the following aliases,

    DESCRIPTION

    Generate port number(s) based on the specified parameters.

    EXAMPLES

    EXAMPLE 1

    PS C:> $port = New-RDMPort -Minimum 50 -Maximum 2048 -IncludeWellKnownPorts -IncludeRegisteredPorts -IncludePortsUsedByOthersSessions

    Generate a port between 50 and 2048. The port can be already used by another session, or be a well known or registered port.

    EXAMPLE 2

    PS C:> $port = New-RDMPort -Minimum 10 -Maximum 15 -IncludeWellKnownPorts -IncludeRegisteredPorts -ExcludePort 11,12,13

    The port will have a value of either 10, 14 or 15. If another session use one of the ports, that port will be excluded from the possibilities.

    EXAMPLE 3

    PS C:> $ports = New-RDMPort -Count 10

    10 ports will be generated and stored in $ports.

    EXAMPLE 4

    PS C:> $sess = Get-RDMSession -Name ARemotePwsh; $sess.PowerShell.Port = New-RDMPort -Minimum 1024; Set-RDMSession -Session $sess -Refresh

    The user fetch an existing remote powershell session called ARemotePwsh and change its port. The new port in at least 1024, not a well known port, not a registered port and unused by other sessions. The user save the modification.

    PARAMETERS

    -Count

    Number of ports to be generated. Default value is 1.

    Type: System.Int32
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    -ExcludePort

    Those ports will not be generated.

    Type: System.Int32[]
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    -ForcePromptAnswer

    Switch to use with caution. It will automatically answer prompt asking yes/no, yes/no/cancel, or ok/cancel questions. In case of multiple prompts, multiple values can be passed to this parameter. Here are the accepted values:

    • Yes: Accept the prompt. Cover the OK and Automatic value.
    • No: Refuse the yes/no/cancel prompt. Cancel is the fallback option if there is not an option No.
    • Cancel: Cancel the yes/no/cancel prompt. No is the fallback option if there is not an option Cancel.
    Type: System.Windows.Forms.DialogResult[]
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    -IncludePortsUsedByOthersSessions

    Allows ports used by others sessions to be generated.

    Type: System.Management.Automation.SwitchParameter
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    -IncludeRegisteredPorts

    Allows registered ports to be generated. For a list of registered ports, see: https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Registered_ports

    Type: System.Management.Automation.SwitchParameter
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    -IncludeWellKnownPorts

    Allows well known ports to be generated. For a list of well known ports, see: https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports

    Type: System.Management.Automation.SwitchParameter
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    -Maximum

    Maximum port value generated. By default, the boundary is set at the absolute maximum 65 535.

    Type: System.Int32
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    -Minimum

    Minimum port value generated. By default, the boundary is set at 0. A recommended value is 1024.

    Type: System.Int32
    DefaultValue: ''
    SupportsWildcards: false
    ParameterValue: []
    Aliases: []
    ParameterSets:
    - Name: (All)
      Position: Named
      IsRequired: false
      ValueFromPipeline: false
      ValueFromPipelineByPropertyName: false
      ValueFromRemainingArguments: false
    DontShow: false
    AcceptedValues: []
    HelpMessage: ''
    

    CommonParameters

    This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

    INPUTS

    OUTPUTS

    NOTES

    For more information, type "Get-Help New-RDMPort -detailed". For technical information, type "Get-Help New-RDMPort -full".