Commands / Sync-sqmDatabaseLogins
Sync-sqmDatabaseLogins
Security sqmSQLTool v1.9.78+ · Sync ✓ -WhatIf supported  ·  ↻ Thin wrapper, no login logic of its own
Thin orchestration wrapper around Export-sqmDatabaseLogins and Import-sqmDatabaseLogins - it has no login/password logic of its own. It exports -Source's SQL-authentication logins for -Database to a throwaway temp file, immediately imports that file against -Destination, and deletes the temp file again. Use this only when one control host/session can reach both instances directly.
ⓘ  If Production and Test sit in domains/networks that cannot see each other, this wrapper cannot help - run Export-sqmDatabaseLogins on the source side, transport the resulting file across the boundary by whatever separate means are available (not part of this module), then run Import-sqmDatabaseLogins on the destination side. Both paths end up doing exactly the same thing; this function only saves the manual two-step dance when connectivity allows it.

Parameters

ParameterTypeRequiredDefaultNotes
-SourcestringRequired, Source SQL Server instance (Production).
-DestinationstringRequired, Destination SQL Server instance (Test).
-DatabasestringRequired, Database whose SQL-authentication users' logins should be synchronized.
-SqlCredentialPSCredentialOptional, Used for both instances. For different credentials use -SourceCredential / -DestinationCredential.
-SourceCredentialPSCredentialOptional, Credential specifically for -Source (overrides -SqlCredential).
-DestinationCredentialPSCredentialOptional, Credential specifically for -Destination (overrides -SqlCredential).
-Loginstring[]Optional, (all)Passed through to Export-sqmDatabaseLogins - restricts to these login names (wildcards).
-ExcludeLoginstring[]Optional, Passed through to Export-sqmDatabaseLogins - additional logins to exclude (wildcards).
-DisablePolicyboolOptional$truePassed through to Import-sqmDatabaseLogins.
-ContinueOnErrorswitchSwitch$falsePassed through to Import-sqmDatabaseLogins.
-EnableExceptionswitchSwitch$falseThrow terminating exceptions immediately instead of returning Failed result objects.

Execution Flow

START 1. Export-sqmDatabaseLogins against -Source Writes to a throwaway temp file under %TEMP% Export Status != Success? YES Warning + return Import is skipped NO 2. Import-sqmDatabaseLogins against -Destination Policy disable/enable + orphan-repair happen here 3. Delete the temp file finally block - always runs, even on error DONE, combined Export+Import results returned

Examples

Sync Frontarena's SQL-auth logins from Prod to Test in one call (both reachable from this session)
Sync-sqmDatabaseLogins -Source 'ProdSQL' -Destination 'TestSQL' -Database 'Frontarena'