Use PowerShell to set TCP Port for SQL to 1433 Use PowerShell to set TCP Port for SQL to 1433 powershell powershell

Use PowerShell to set TCP Port for SQL to 1433


Updated to show results of each command

You have mistakes / missing things in your code.

Try this approach...

'Loading SQLPS environment'Import-Module SQLPS -DisableNameChecking -ForceResultsLoading SQLPS environment'Initializing WMI object and Connect to the instance using SMO'($Wmi = New-Object ('Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer') $env:COMPUTERNAME)ResultsInitializing WMI object and Connect to the instance using SMOConnectionSettings : Microsoft.SqlServer.Management.Smo.Wmi.WmiConnectionInfoServices           : {MSSQLFDLauncher, MSSQLSERVER, SQLBrowser, SQLSERVERAGENT}ClientProtocols    : {np, sm, tcp}ServerInstances    : {MSSQLSERVER}ServerAliases      : {}Urn                : ManagedComputer[@Name='SQL01']Name               : SQL01Properties         : {}UserData           : State              : Existing($uri = "ManagedComputer[@Name='$env:COMPUTERNAME']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']")ResultsManagedComputer[@Name='SQL01']/ ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']# Getting settings($Tcp = $wmi.GetSmoObject($uri))ResultsParent              : Microsoft.SqlServer.Management.Smo.Wmi.ServerInstanceDisplayName         : TCP/IPHasMultiIPAddresses : TrueIsEnabled           : TrueIPAddresses         : {IP1, IP2, IP3, IP4...}ProtocolProperties  : {Enabled, KeepAlive, ListenOnAllIPs}Urn                 : ManagedComputer[@Name='SQL01']/ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']Name                : TcpProperties          : {Name=DisplayName/Type=System.String/Writable=False/Value=TCP/IP, Name=HasMultiIPAddresses/Type=System.Boolean/Writable=False/Value=True,                       Name=IsEnabled/Type=System.Boolean/Writable=True/Value=True}UserData            : State               : Creating$Tcp.IsEnabled = $true($Wmi.ClientProtocols)Parent             : Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputerDisplayName        : Named PipesIsEnabled          : TrueNetworkLibrary     : SQLNCLI11Order              : 3NetLibInfo         : Microsoft.SqlServer.Management.Smo.Wmi.NetLibInfoProtocolProperties : {Default Pipe}Urn                : ManagedComputer[@Name='SQL01']/ClientProtocol[@Name='np']Name               : npProperties         : {Name=DisplayName/Type=System.String/Writable=False/Value=Named Pipes, Name=IsEnabled/Type=System.Boolean/Writable=True/Value=True,                      Name=NetworkLibrary/Type=System.String/Writable=False/Value=SQLNCLI11, Name=Order/Type=System.Int32/Writable=True/Value=3}UserData           : State              : ExistingParent             : Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputerDisplayName        : Shared MemoryIsEnabled          : TrueNetworkLibrary     : SQLNCLI11Order              : 1NetLibInfo         : Microsoft.SqlServer.Management.Smo.Wmi.NetLibInfoProtocolProperties : {}Urn                : ManagedComputer[@Name='SQL01']/ClientProtocol[@Name='sm']Name               : smProperties         : {Name=DisplayName/Type=System.String/Writable=False/Value=Shared Memory, Name=IsEnabled/Type=System.Boolean/Writable=True/Value=True,                      Name=NetworkLibrary/Type=System.String/Writable=False/Value=SQLNCLI11, Name=Order/Type=System.Int32/Writable=True/Value=1}UserData           : State              : ExistingParent             : Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputerDisplayName        : TCP/IPIsEnabled          : TrueNetworkLibrary     : SQLNCLI11Order              : 2NetLibInfo         : Microsoft.SqlServer.Management.Smo.Wmi.NetLibInfoProtocolProperties : {Default Port, KEEPALIVE (in milliseconds), KEEPALIVEINTERVAL (in milliseconds)}Urn                : ManagedComputer[@Name='SQL01']/ClientProtocol[@Name='tcp']Name               : tcpProperties         : {Name=DisplayName/Type=System.String/Writable=False/Value=TCP/IP, Name=IsEnabled/Type=System.Boolean/Writable=True/Value=True,                      Name=NetworkLibrary/Type=System.String/Writable=False/Value=SQLNCLI11, Name=Order/Type=System.Int32/Writable=True/Value=2}UserData           : State              : Existing$wmi.GetSmoObject($uri + "/IPAddress[@Name='IPAll']").IPAddressPropertiesName       : TcpDynamicPortsValue      : Type       : System.StringWritable   : TrueReadable   : TrueExpensive  : FalseDirty      : FalseRetrieved  : TrueIsNull     : FalseEnabled    : FalseRequired   : FalseAttributes : {}Name       : TcpPortValue      : 14433Type       : System.StringWritable   : TrueReadable   : TrueExpensive  : FalseDirty      : FalseRetrieved  : TrueIsNull     : FalseEnabled    : FalseRequired   : FalseAttributes : {}'Setting IP Properties'$wmi.GetSmoObject($uri + "/IPAddress[@Name='IPAll']").IPAddressProperties[1].Value="1433"'Review properties'$wmi.GetSmoObject($uri + "/IPAddress[@Name='IPAll']").IPAddressPropertiesName       : TcpDynamicPortsValue      : Type       : System.StringWritable   : TrueReadable   : TrueExpensive  : FalseDirty      : FalseRetrieved  : TrueIsNull     : FalseEnabled    : FalseRequired   : FalseAttributes : {}Name       : TcpPortValue      : 1433Type       : System.StringWritable   : TrueReadable   : TrueExpensive  : FalseDirty      : FalseRetrieved  : TrueIsNull     : FalseEnabled    : FalseRequired   : FalseAttributes : {}'Save properties'$Tcp.Alter()'Review properties'$wmi.GetSmoObject($uri + "/IPAddress[@Name='IPAll']").IPAddressPropertiesName       : TcpDynamicPortsValue      : Type       : System.StringWritable   : TrueReadable   : TrueExpensive  : FalseDirty      : FalseRetrieved  : TrueIsNull     : FalseEnabled    : FalseRequired   : FalseAttributes : {}Name       : TcpPortValue      : 1433Type       : System.StringWritable   : TrueReadable   : TrueExpensive  : FalseDirty      : FalseRetrieved  : TrueIsNull     : FalseEnabled    : FalseRequired   : FalseAttributes : {}