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

Please note that documentation and command names may be out of date while we work furiously towards 1.0


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.




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



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


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