This script will read a list of servers and check, update, create, delete or "delete all" new SQL Alias(s) registry keys from within the 32bit and 64bit hives.
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\MSSQLServer\Client\ConnectTo
This is useful when migrating SharePoint servers to a new SQL server, where the SQL instance will change but the alias will remain the same.
How to run:
-
Create a list of servers in the "Servers.txt" file.
Note: Make sure your path is correct
-
Modify the "$sqlalias" and the "$sqlServer" parameters to match your environment.
Note: These settings can a new entry or a current setting you want to update.
Please note: When using TCP/IP, "DBMSSOCN, will be added to the string in the registry and a Port number maybe required.
-
Run the script from a server with an elevated PowerShell ISE or PowerShell.
-
The "Check" option will read the current key(s) across your list of servers and output all alias's and the configurations to a file in the Temp location.
Example:
-
The "Update" option will change the keys according to the names you specified in the inputs:
Example:
-
The "Create" option will add a new entry in both the 32bit and 64bit hives if one does not exists.
Example:
-
The "Delete" option will delete the specified value in both the 32bit and 64bit "Connect to" keys.
Example:
-
The "DeleteAll" option will delete all values in both the 32bit and 64bit "Connect to" keys.
Note: Use this option with caution as it will delete all current SQL Alias's and could impact your service if this action is not totally understood.
Example: