Create SQL Server Alias using PowerShell

As per SharePoint best practices for SQL Server, SQL Alias needs to be created on all SharePoint Servers in the farm. Creating SQL Alias for SharePoint through UI, is already explained in my another post: Create SQL Server Alias for SharePoint , and here is the PowerShell version of creating SQL Server Alias.

#Name of your SQL Server Alias
$AliasName = "SP13_PROD_SQL"

# Actual SQL Server Name
$SQLServerName = "G1VSP13-SQLC001" 

#TCP Port
$Port = "1433"

#These are the two Registry locations for the SQL Alias 
$x86 = "HKLM:\Software\Microsoft\MSSQLServer\Client\ConnectTo"
$x64 = "HKLM:\Software\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo"

#if the ConnectTo key doesn't exists, create it.
if ((test-path -path $x86) -ne $True)
{
    New-Item $x86
}

if ((test-path -path $x64) -ne $True)
{
    New-Item $x64
}

#Define SQL Alias 
$TCPAliasName = "DBMSSOCN,$SQLServerName,$Port"

#Create TCP/IP Aliases
New-ItemProperty -Path $x86 -Name $AliasName -PropertyType String -Value $TCPAliasName
New-ItemProperty -Path $x64 -Name $AliasName -PropertyType String -Value $TCPAliasName

finally, open these two executables to verify:

  • C:\Windows\System32\cliconfg.exe
  • C:\Windows\SysWOW64\cliconfg.exe
create sql alias for sharepoint 2013 powershell
create sql alias for sharepoint 2016

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

3 thoughts on “Create SQL Server Alias using PowerShell

  • February 20, 2021 at 4:59 PM

    I realize this was 3 years ago, but just curious if you tried rebooting or restarting the sql service since this is inherently a registry modification that might not be picked up right away.

    Reply
  • May 3, 2018 at 1:58 AM

    This way does not properly create the alias using TCP/IP. I tried it and experienced SQL errors when trying to create the farm and configuration database.

    When I manually changed the alias to use TCP/IP, it then succeeded.

    Reply
  • February 2, 2018 at 11:23 PM

    Can you tell me how I can add enabling/disabling the TCP/IP and Pipes protocols in this script?

    Reply

Leave a Reply