<#====================================================================
Copyright © 2015, September. Michael Pomfret
Adds the SQL Server client alias
The script only targets the server you are running the script on
and does the following:
-Adds the SQL Server client alias
====================================================================#>
#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window
If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)
{
Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null
}
<#====================================================================
Get SharePoint variables
====================================================================#>
Add-Module(“C:\Temp\SharePoint2013\GetVariables.ps1”)
function Add-Module($strFileName){
Write-Host “Attempting to run ” $strFileName
If (Test-Path $strFileName){
&($strFileName)
}Else{
Write-Host “Cannot locate” $strFileName
}
}
Write-Host “SharePoint 2013 – Adding the SQL Server client alias…”
#This is the name of your SQL Alias
$AliasName = “SPFarmAlias”
#This is the name of your SQL server (the actual name!)
# In this case we’re using the SQL Server name is defined in the SharePoint Variables text file
#These are the two Registry locations for the SQL Alias locations
$x86 = “HKLM:\Software\Microsoft\MSSQLServer\Client\ConnectTo”
$x64 = “HKLM:\Software\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo”
#We’re going to see if the ConnectTo key already exists, and create it if it doesn’t.
if ((test-path -path $x86) -ne $True)
{
write-host “$x86 doesn’t exist”
New-Item $x86
}
if ((test-path -path $x64) -ne $True)
{
write-host “$x64 doesn’t exist”
New-Item $x64
}
#Adding the TCPIP Alias
$TCPAlias = (“DBMSSOCN,” + $DBServer)
#Creating our TCP/IP Aliases
New-ItemProperty -Path $x86 -Name $AliasName -PropertyType String -Value $TCPAlias
New-ItemProperty -Path $x64 -Name $AliasName -PropertyType String -Value $TCPAlias
# Open cliconfig to verify the aliases
#Start-Process C:\Windows\System32\cliconfg.exe
#Start-Process C:\Windows\SysWOW64\cliconfg.exe