Configuration

Set-sqmTcpPort

Calculates and sets the SQL Server TCP port via the Windows Registry — supports named instances with automatic port calculation based on a base port plus instance number offset.

Module: sqmSQLTool
Requires: Registry (no dbatools)
ShouldProcess: No
Output: PSCustomObject

Execution Flow

START -InstanceNumber provided? Yes Port = BasePort + PortIncrement * InstanceNumber No (use BasePort) 1. Parse SqlInstance → extract computer name + instance name 2. Resolve registry key: HKLM\...\SuperSocketNetLib\Tcp\IPAll Registry key found? throw error 3. Read previous TcpPort value 4. Set-ItemProperty TcpPort = calculated port / clear TcpDynamicPorts Return PSCustomObject (SqlInstance, Port, PreviousPort, Status, Message) DONE
The SQL Server Browser service and SQL Server service must be restarted manually after the port change takes effect. Dynamic port assignment (TcpDynamicPorts) is cleared automatically when a static port is set. Remote registry access requires appropriate permissions and the RemoteRegistry service running on the target.

Parameters

ParameterTypeRequiredDescription
-SqlInstanceStringRequiredSQL Server instance. Format: Server or Server\Instance.
-BasePortIntOptionalBase TCP port. Default: 1433.
-PortIncrementIntOptionalPort offset per instance number. Default: 10.
-InstanceNumberIntOptionalInstance number for port calculation: Port = BasePort + PortIncrement × InstanceNumber. Default: -1 (use BasePort directly).

Return Value

Returns a PSCustomObject with: SqlInstance, Port, PreviousPort, Status, Message.

Examples

Example 1 — Set default instance to port 1433

Set-sqmTcpPort -SqlInstance "SQL01"

Example 2 — Named instance with calculated port (1433 + 10×2 = 1453)

Set-sqmTcpPort -SqlInstance "SQL01\INST02" -BasePort 1433 -PortIncrement 10 -InstanceNumber 2

Example 3 — Explicit port without calculation

Set-sqmTcpPort -SqlInstance "SQL01\NAMED" -BasePort 1455