• Not sure why you are looking for script to edit port number.

    You can use xp_regwrite SP to edit port number in registry keys. But its not recommended to edit reg keys. Using Configuration Manager is the right option.