dbatools is a free PowerShell module with over 180 SQL Server administration, best practice and migration commands included.


Repair-DbaServerName

When a SQL Server’s host OS is renamed, the SQL Server should be as well. This helps with Availability Groups and Kerberos. This command renames @@SERVERNAME to match with the Windows name. The new name is automatically determined. It does not matter if you use an alias to connect to the SQL instance.

If the automatically determined new name matches the old name, the command will not run.

Renaming clusters is not supported by this command because renaming clustered instances is not supported by Microsoft.

NOTE: This has only been tested in a lab environment. It was successfully tested against a number of servers (SQL2005/2014/2016 on Windows 7/2008/2012), but could still use testing, especially if mirroring is enabled. If you can test this and let us know how it works for you, we’d appreciate it.

Screenshots

repair-dbaservername

Examples

Checks to see if the server is updatable, prompts galore, changes name.

Repair-DbaServerName -SqlServer sql2014

Even more prompts/confirms, but removes Replication or breaks mirroring if necessary.

Repair-DbaServerName -SqlServer sql2014 -AutoFix

Skips some prompts/confirms but not all of them.

Repair-DbaServerName -SqlServer sql2014 -AutoFix -Force

Additional Screenshot

repair-dbaservername-withblockers

References

Steps to change the server name for a SQL Server machine – Jugal Shah, mssqltips.com

Get-Help

From PowerShell, execute Get-Help Repair-DbaServerName -Detailed for more information on this function.

Source Code

Want to see the source code? View Repair-DbaServerName.ps1 on GitHub
 

Related commands