Sync-sqmDatabaseLogins
Security
sqmSQLTool v1.9.78+ · Sync
✓ -WhatIf supported · ↻ Thin wrapper, no login logic of its own
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
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -Source | string | Required | , | Source SQL Server instance (Production). |
| -Destination | string | Required | , | Destination SQL Server instance (Test). |
| -Database | string | Required | , | Database whose SQL-authentication users' logins should be synchronized. |
| -SqlCredential | PSCredential | Optional | , | Used for both instances. For different credentials use -SourceCredential / -DestinationCredential. |
| -SourceCredential | PSCredential | Optional | , | Credential specifically for -Source (overrides -SqlCredential). |
| -DestinationCredential | PSCredential | Optional | , | Credential specifically for -Destination (overrides -SqlCredential). |
| -Login | string[] | Optional | , (all) | Passed through to Export-sqmDatabaseLogins - restricts to these login names (wildcards). |
| -ExcludeLogin | string[] | Optional | , | Passed through to Export-sqmDatabaseLogins - additional logins to exclude (wildcards). |
| -DisablePolicy | bool | Optional | $true | Passed through to Import-sqmDatabaseLogins. |
| -ContinueOnError | switch | Switch | $false | Passed through to Import-sqmDatabaseLogins. |
| -EnableException | switch | Switch | $false | Throw terminating exceptions immediately instead of returning Failed result objects. |
Execution Flow
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'