Commands / Get-sqmSaLogin
Get-sqmSaLogin
Security sqmSQLTool v1.8.2+ · Utility
Resolves the CURRENT name of the built-in sa account on a SQL Server instance, by looking it up via its fixed SID (0x01) rather than the literal string "sa". This matters because the account's name isn't guaranteed to still be "sa": Invoke-sqmSaObfuscation renames and disables it as a security hardening step, and once that has run, any code that hardcodes "sa" silently stops working. Internally used by Invoke-sqmRestoreDatabase to set the correct database owner after a restore, regardless of whether the account has been renamed.
Fails quietly: on any error (connection failure, insufficient permissions, ...) this returns $null instead of throwing - callers are expected to check the result rather than wrap every call in a try/catch.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestringRequired,
-SqlCredentialPSCredentialOptional,

Examples

Get the current name of the sa account, whatever it's been renamed to
Get-sqmSaLogin -SqlInstance "SQL01"
Use the result to set a database owner correctly, even after sa-obfuscation
$saName = Get-sqmSaLogin -SqlInstance "SQL01"
if ($saName) { Set-DbaDbOwner -SqlInstance "SQL01" -Database "arena" -TargetLogin $saName }