I have an unattended installation of SQL Server 2016 using the .INI
answer file. In my answer file, I enable TCP like this:
; Specify 0 to disable or 1 to enable the TCP/IP protocol.
TCPENABLED="1"
Once the installation is finished, I also create an alias using a PowerShell script. So far so good. However, the SQL Server instance is installed with dynamic ports enabled and I can't see a way to specify a static TCP port (I want to use the standard 1433) in the answer file. Hence the alias won't work.
How can I set a static TCP port, either via the answer file, or using PowerShell?
After long hours searching for a viable solution I came up with this PowerShell function that can set the TCP port of a specific SQL Server instance:
Now, this function is used like this:
The script shall be run elevated, i.e. Run as Administrator.
Credits go to this blog post which pointed me to the right direction.