Skip to content

Instantly share code, notes, and snippets.

@IlyaFinkelshteyn
Created October 6, 2016 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IlyaFinkelshteyn/1b0436f3935f078fec1cf593b6608019 to your computer and use it in GitHub Desktop.
Save IlyaFinkelshteyn/1b0436f3935f078fec1cf593b6608019 to your computer and use it in GitHub Desktop.
param ([string] $instance, [string] $port )
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | Out-Null
[reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SqlWmiManagement") | Out-Null
$serverName = $env:COMPUTERNAME
$smo = 'Microsoft.SqlServer.Management.Smo.'
$wmi = new-object ($smo + 'Wmi.ManagedComputer')
$uri = "ManagedComputer[@Name='$serverName']/ServerInstance[@Name='$instance']/ServerProtocol[@Name='Tcp']"
$tcp = $wmi.GetSmoObject($uri)
$tcp.IsEnabled = $true
foreach ($ipAddress in $tcp.IPAddresses) {
$ipAddress.IPAddressProperties["TcpDynamicPorts"].Value = ""
$ipAddress.IPAddressProperties["TcpPort"].Value = $port
}
$tcp.Alter()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment