> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell/powershell-commands/new-rdmport.md).

# 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>]
```

### Description

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

### Examples

#### Example 1

```powershell
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

```powershell
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

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

10 ports will be generated and stored in $ports.

#### Example 4

```powershell
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.

```yaml
Type: System.Int32
DefaultValue: ''
SupportsWildcards: false
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.

```yaml
Type: System.Int32[]
DefaultValue: ''
SupportsWildcards: false
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 no "No" option.
* Cancel: Cancel the yes/no/cancel prompt. "No" is the fallback option if there is no "Cancel" option.

```yaml
Type: System.Windows.Forms.DialogResult[]
DefaultValue: ''
SupportsWildcards: false
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.

```yaml
Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
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>

```yaml
Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
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>

```yaml
Type: System.Management.Automation.SwitchParameter
DefaultValue: ''
SupportsWildcards: false
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.

```yaml
Type: System.Int32
DefaultValue: ''
SupportsWildcards: false
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.

```yaml
Type: System.Int32
DefaultValue: ''
SupportsWildcards: false
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](https://go.microsoft.com/fwlink/?LinkID=113216).

### Notes

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell/powershell-commands/new-rdmport.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
