Export-sqmDatabaseLogins
Security
sqmSQLTool v1.9.78+ · Export
✓ -WhatIf supported · ⚠ sysadmin/sa logins are never exported, no override
Import-sqmDatabaseLogins. Built for databases like an application copy that is periodically refreshed from Production to Test (e.g. one with hundreds or thousands of SQL logins): the restore itself brings the database users over correctly, but the matching server-level logins - and in particular their current password - normally live only on Production and drift out of sync on Test as passwords change there over time. Only -SqlInstance (the source) is ever contacted; getting the generated file to wherever Import-sqmDatabaseLogins will read it is a separate, external transport this function does not perform.
ⓘ Sysadmin/'sa' logins (detected dynamically via the well-known SID
0x01 and is_srvrolemember('sysadmin', ...), independent of any rename) are excluded from every export with no override switch. The generated script repeats this check a second time, inside every single per-login block, so it stays safe even if hand-run against the wrong instance later.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Required | , | Source SQL Server instance (Production). Only this instance is ever contacted. |
| -SqlCredential | PSCredential | Optional | , | Credential for -SqlInstance. |
| -Database | string | Required | , | Database whose SQL-authentication users' logins should be exported. |
| -OutputPath | string | Required | , | Full file path, or an existing/creatable directory (auto-named DatabaseLogins_<Database>_<SqlInstance>_<timestamp>.sql inside it). Any path is accepted - local disk, UNC share, etc. |
| -Login | string[] | Optional | , (all) | Restricts the export to these login names (wildcards allowed). |
| -ExcludeLogin | string[] | Optional | , | Additional logins to exclude (wildcards allowed), e.g. a shared service account that should keep an independent Test-side password. |
| -EnableException | switch | Switch | $false | Throw terminating exceptions immediately instead of returning a Failed result object. |
Execution Flow
Examples
Export every SQL-auth login backing Frontarena to a share for an external cross-domain copy job
Export-sqmDatabaseLogins `
-SqlInstance 'ProdSQL' `
-Database 'Frontarena' `
-OutputPath '\\Share\Handover\Frontarena_Logins.sql'Export into an auto-named file, skipping a shared service account that keeps its own Test password
Export-sqmDatabaseLogins `
-SqlInstance 'ProdSQL' `
-Database 'Frontarena' `
-OutputPath 'C:\Temp' `
-ExcludeLogin 'SvcAccount_*'