Restore-sqmSysadminAccess
Security
sqmSQLTool v1.9.85+ · Restore
✓ -WhatIf supported · ⚠ stops the SQL service temporarily
-m"<marker>" startup parameter (single-user mode), use the one connection SQL Server allows in that mode — which grants any local Windows Administrator implicit sysadmin rights regardless of their actual SQL login — to create (or reset the password of and re-enable) the specified SQL-Auth login and add it to the fixed server role sysadmin, then tear the single-user mode back down and restart the service normally. Every step of that teardown runs in a finally block, so the service is put back into normal multi-user operation even if something failed partway through.
ⓘ Single-user mode allows exactly one connection. Login creation/reset, the
sysadmin grant, and verification therefore all run in a single T-SQL batch over a single connection — any extra round-trip would be a window in which another process (a monitoring agent reconnecting the instant the service comes back up, for example) could grab that one slot first and make the whole procedure fail. The same batch also temporarily disables every currently-enabled server-wide DDL trigger and re-enables exactly those afterward, because the built-in syspolicy_server_trigger (Policy-Based Management) can silently roll back CREATE LOGIN/ALTER SERVER ROLE even inside single-user mode — see Invoke-sqmTempSysadminAction for the incident that surfaced this originally.
⚠ Requires Windows-Integrated Authentication to work between the machine running this command and the target instance (that's how SQL Server verifies you're a local Administrator inside single-user mode). Across a workgroup boundary without matching local credentials, or wherever NTLM double-hop is blocked, that authentication fails — run this directly on the affected SQL Server box for it to work reliably, exactly like the real-world procedure it automates.
ⓘ Unlike Grant-sqmTemporarySysadmin, the interactive
Confirm prompt (ConfirmImpact 'High') is not suppressed by default — this is meant as a manual break-glass action performed by someone at the keyboard during an incident, not unattended automation. A pre-flight check also refuses to run (unless -Force) if the instance is already reachable with sysadmin rights under the current Windows account, and a best-effort local check warns/aborts if the target looks like a Windows Server Failover Cluster node, where stopping the service directly (instead of via the cluster resource) can conflict with the cluster service.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | $env:COMPUTERNAME | Default instance of the local computer, or SERVER\INSTANCE. |
| -Login | string | Required | , | SQL-Auth login to grant emergency access. Reset+re-enabled if it already exists, otherwise created. |
| -Password | SecureString | Optional | , (auto-generated) | Without it, a 24-char policy-compliant password is generated (New-sqmRandomSaPassword) and returned in plain text in the output object — never logged. |
| -TimeoutSeconds | int | Optional | 120 | Max wait (30–900s) for the restarted service to accept the single-user connection. |
| -TicketNumber | string | Optional | , | Written to the module log and Windows Event Log for traceability. |
| -Force | switch | Switch | $false | Skips the "already sysadmin reachable" pre-flight check and the local Failover-Cluster warning/abort. |
Execution Flow
Examples
Emergency access, generated password, with ticket number
Restore-sqmSysadminAccess `
-SqlInstance SQL01 `
-Login 'sqm_emergency' `
-TicketNumber 'INC0099887'Reset a known login (e.g. sa) to a self-chosen password, skip the pre-flight/cluster checks
$securePw = Read-Host -AsSecureString 'New password' Restore-sqmSysadminAccess -Login 'sa' -Password $securePw -Force
Local instance (recommended usage: run directly on the affected SQL Server)
Restore-sqmSysadminAccess -Login 'sqm_emergency' -TicketNumber 'INC0099887'
Preview only — shows what would happen, service is never touched
Restore-sqmSysadminAccess -SqlInstance SQL01 -Login 'sqm_emergency' -WhatIf
Longer timeout for a slow-starting instance, then rotate/remove the account afterward
$r = Restore-sqmSysadminAccess -SqlInstance SQL01 -Login 'sqm_emergency' -TimeoutSeconds 300 $r | Select-Object SqlInstance, Login, LoginExisted, Status # ... regain regular access, then rotate or remove 'sqm_emergency' again ...