Created
October 6, 2016 17:15
-
-
Save IlyaFinkelshteyn/1b0436f3935f078fec1cf593b6608019 to your computer and use it in GitHub Desktop.
This file contains 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
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