Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fireflycons/58dfde9c2fab7de2f4e97668938baebe to your computer and use it in GitHub Desktop.
Save fireflycons/58dfde9c2fab7de2f4e97668938baebe to your computer and use it in GitHub Desktop.
Enable dynamic TCP ports for all SQL Server instances (so they can be run simultaneously)
<#
.SYNOPSIS
Set all installed instances of SQL server to dynamic ports
#>
Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\' |
Where-Object {
$_.Name -imatch 'MSSQL[_\d]+\.SQL.*'
} |
ForEach-Object {
Write-Host "Setting $((Get-ItemProperty $_.PSPath).'(default)') to dynamic ports"
Set-ItemProperty (Join-Path $_.PSPath 'mssqlserver\supersocketnetlib\tcp\ipall') -Name TcpDynamicPorts -Value '0'
Set-ItemProperty (Join-Path $_.PSPath 'mssqlserver\supersocketnetlib\tcp\ipall') -Name TcpPort -Value ([string]::Empty)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment