Created
August 25, 2015 20:02
-
-
Save stefanteixeira/12208058dd0894ce0873 to your computer and use it in GitHub Desktop.
PowerShell script to enable TCP in SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Import-Module "sqlps" | |
| $smo = 'Microsoft.SqlServer.Management.Smo.' | |
| $wmi = new-object ($smo + 'Wmi.ManagedComputer'). | |
| # List the object properties, including the instance names. | |
| $Wmi | |
| # Enable the TCP protocol on the default instance. | |
| $uri = "ManagedComputer[@Name='" + (get-item env:\computername).Value + "']/ServerInstance[@Name='MSSQLSERVER']/ServerProtocol[@Name='Tcp']" | |
| $Tcp = $wmi.GetSmoObject($uri) | |
| $Tcp.IsEnabled = $true | |
| $Tcp.Alter() | |
| $Tcp |
Just sharing, the sql server express container image does the same thing but with registry keys. From the DockerFile
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql13.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value '' ; \
set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql13.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433 ; \
Author
Sorry @geradev, it's been more than 5 years I don't work with that, didn't even worked with Windows since then 😕
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Does this work with SQL Server Express? I'm trying the following
$wmi.GetSmoObject("ManagedComputer[@Name='$env:COMPUTERNAME']works fine but there is a propertyServerInstancesand notServerInstancebut in my case it's empty.I've installed SQL Server Express using Chokolatey