Repair-sqmServerName
SQL Configuration
sqmSQLTool v1.8.2+ · Repair
✓ -WhatIf supported
@@SERVERNAME / sys.servers) with the current Windows hostname or FQDN, after the machine was renamed (e.g. after a VM clone or datacenter move). Windows reports the new name immediately (SERVERPROPERTY('MachineName')), but SQL Server keeps the OLD name as its "local server" entry until sp_dropserver/sp_addserver is run, a drift that often only surfaces once replication, linked-server loopbacks, SSRS, or certificates start failing against the wrong name.
Guard checks before touching anything: the function does NOT blindly run
sp_dropserver/sp_addserver on a mismatch. It first checks failover-cluster membership (IsClustered), AlwaysOn AG membership (sys.availability_replicas.replica_server_name), and replication roles (sys.databases: distributor/publisher/subscriber/merge-publisher). In all of these cases other objects still reference the old name, a plain rename would succeed technically but break those references, so the function aborts with Status = 'Blocked' instead. Use -Force only once those references are handled separately or the breakage is accepted deliberately.Restart required:
sys.servers is updated immediately, but the session-level @@SERVERNAME/SERVERPROPERTY('ServerName') only reflects the change after the SQL Server service is restarted. This function does NOT restart the service itself, it sets RestartRequired = $true in the result and stops there.Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Position 0. |
| -SqlCredential | PSCredential | Optional | , | Default: Windows Authentication. |
| -Force | switch | Switch | $false | Skips the cluster/AG/replication guard checks and forces the rename anyway. |
| -EnableException | switch | Switch | $false | Throws exceptions instead of only reporting them in the result object. |
Execution Flow
Return Value
| Property | Description |
|---|---|
| SqlInstance | Instance name, as passed in. |
| RegisteredServerName | @@SERVERNAME before the change. |
| ExpectedServerName | Target name computed from MachineName/InstanceName. |
| IsClustered | SERVERPROPERTY('IsClustered') = 1? |
| Status | AlreadyCorrect · Changed · Blocked · WhatIf · Error |
| RestartRequired | $true if a service restart is still pending for @@SERVERNAME to reflect the new value. |
| Message | Human-readable detail message. |
Examples
Check the local default instance and repair if needed (with guard checks)
Repair-sqmServerName
Preview only, show which sp_dropserver/sp_addserver steps would run
Repair-sqmServerName -SqlInstance "SQL01\INST01" -WhatIf
Force the rename even though AG/replication/cluster references were detected
Repair-sqmServerName -SqlInstance "SQL01" -Force -Confirm:$false