Skip to content

Instantly share code, notes, and snippets.

@stefanteixeira
Created August 25, 2015 20:02
Show Gist options
  • Save stefanteixeira/12208058dd0894ce0873 to your computer and use it in GitHub Desktop.
Save stefanteixeira/12208058dd0894ce0873 to your computer and use it in GitHub Desktop.
PowerShell script to enable TCP in SQL Server
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
@GeradeDev
Copy link

Hi, thanks for the script. I am trying to run on a couple of servers but on some of the servers, the WMI object does not have the SQL server instance listed. See image below:

image

Do you have any suggestions?

@stefanteixeira
Copy link
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