Copy-sqmLogins
Security
sqmSQLTool v1.8.2+ · Copy
✓ -WhatIf supported · ⚠ Policy re-enabled via finally block
AdOrphan, (5) copy via Copy-DbaLogin with password hash and SID mapping, (6) repair orphaned users on all target databases, (7) re-enable policy — guaranteed via finally block even on unhandled errors.
ⓘ The sa account is always excluded regardless of
-IncludeSystemLogins — it is detected via its well-known SID 0x01, so renamed sa accounts are safely excluded too. If source uses Mixed Mode and target is Windows-only, the function aborts unless -AdjustAuthMode is specified.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -Source | string | Required | — | Source SQL Server instance. |
| -Destination | string | Required | — | Target SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | Used for both source and target. For different credentials use -SourceCredential / -DestinationCredential. |
| -SourceCredential | PSCredential | Optional | — | Credential specifically for the source instance. |
| -DestinationCredential | PSCredential | Optional | — | Credential specifically for the target instance. |
| -Login | string[] | Optional | — (all) | Filter: only copy these logins (wildcards allowed). |
| -ExcludeLogin | string[] | Optional | — | Logins to exclude from the copy (wildcards allowed). |
| -IncludeSystemLogins | switch | Switch | $false | Also copies NT SERVICE\*, NT AUTHORITY\*, BUILTIN\* logins. The sa account (SID 0x01) is ALWAYS excluded regardless of this switch. |
| -DisablePolicy | bool | Optional | $true | Disables the configured DefaultPolicy on the target before copying and re-enables it afterwards via finally block. |
| -AdjustAuthMode | switch | Switch | $false | Switches target to Mixed Mode if source is Mixed Mode and target is Windows-only. Without this switch the function aborts on mode mismatch. |
| -RestartServiceIfRequired | switch | Switch | $false | Automatically restarts the SQL Server service on the target after an auth mode change. |
| -Force | switch | Switch | $false | Overwrites existing logins on the target. |
| -AdModuleAction | string | Optional | Install | Behavior when ActiveDirectory module is missing: Install (auto-install), Skip (skip AD check), Abort (error). |
| -ContinueOnError | switch | Switch | $false | Continue with next login on error instead of aborting. |
| -EnableException | switch | Switch | $false | Throw terminating exceptions immediately. |
Execution Flow
Examples
Copy all non-system logins — AD check and orphan repair included
Copy-sqmLogins -Source 'SQL01' -Destination 'SQL02'
Copy with auth mode alignment and automatic service restart
Copy-sqmLogins `
-Source 'SQL01' `
-Destination 'SQL02' `
-AdjustAuthMode `
-RestartServiceIfRequiredCopy only App_ logins, overwrite existing, preview with -WhatIf
Copy-sqmLogins `
-Source 'SQL01' `
-Destination 'SQL02' `
-Login 'App_*' `
-Force `
-WhatIfCopy without policy handling; abort on AD module missing
Copy-sqmLogins `
-Source 'SQL01' `
-Destination 'SQL02' `
-DisablePolicy $false `
-AdModuleAction Abort `
-EnableException