Vlad Drumea doesn’t want a dynamic port number:
This post demos a script that I’ve put together to automate the configuration of the static TCP port for a SQL Server instance using PowerShell.
The script is derived from another PowerShell script that I’ve written to help spin up SQL Server test instances in my home lab.
This should be helpful you’re working in a restrictive environment where you can’t install additional PowerShell modules, and you couldn’t take advantage of dbatools’ Set-DbaTcpPort.
Click through for the script, but also use dbatools whenever you can because it’s a good product and I haven’t done any unpaid shilling for them in far too long.