Import-sqmDatabaseLogins
Security
sqmSQLTool v1.9.78+ · Import
✓ -WhatIf supported · ⚠ Policy re-enabled via finally block
Export-sqmDatabaseLogins. Reads the self-contained T-SQL script that function wrote - already placed at -InputPath by some external, separately controlled transport (file share, scheduled copy job, ...) since source and destination may sit in domains/networks that cannot reach each other directly - and applies it against -SqlInstance (the destination, e.g. Test). Only the destination is ever contacted; there is no connection back to the original source. Every login block is executed individually rather than as one combined script, so each of the potentially thousands of logins gets its own result (Success / SkippedSysadmin / SkippedSidCollision / Failed) instead of one all-or-nothing outcome.
ⓘ A block's own PRINT output - emitted when it deliberately left a sysadmin/'sa' login alone, or found a SID already claimed by a differently-named login - is captured and reflected in that login's result Status. The sysadmin protection built into the file is therefore auditable here, not a silent no-op.
Repair-DbaDbOrphanUser always runs last against -Database, exactly as Invoke-sqmRestoreDatabase and Copy-sqmLogins already do after any login change.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Required | , | Destination SQL Server instance (e.g. Test). Only this instance is ever contacted. |
| -SqlCredential | PSCredential | Optional | , | Credential for -SqlInstance. |
| -InputPath | string | Required | , | Path to the .sql file produced by Export-sqmDatabaseLogins, already transported here by an external process, or a directory (v1.9.161+). With a directory, the newest export for -Database is used: header must name exactly that database, newest by the timestamp in the file name (not LastWriteTime), source instance irrelevant, .tmp files ignored. The chosen file is reported as the first result row (SelectFile). |
| -Database | string | Required | , | Database to run the final orphan-user repair against. Compared to the database name recorded in the file's header - a mismatch only warns, it does not block the run. |
| -DisablePolicy | bool | Optional | $true | Disables the configured DefaultPolicy on the destination before applying the logins and re-enables it afterwards via finally block. |
| -KeepLatest | int | Optional | 0 | Directory form only (v1.9.161+): after the import, keep this many of the newest exports for -Database in that directory and delete the older ones. 0 deletes nothing, since the destination directory is often owned by the transport job. |
| -ContinueOnError | switch | Switch | $false | Continue with the next login block if one fails, instead of aborting the whole run. |
| -EnableException | switch | Switch | $false | Throw terminating exceptions immediately (overrides -ContinueOnError). |
Execution Flow
Examples
Apply a previously exported login file to Test and repair orphaned users afterwards
Import-sqmDatabaseLogins `
-SqlInstance 'TestSQL' `
-Database 'Frontarena' `
-InputPath 'D:\Handover\Frontarena_Logins.sql'Apply without policy handling, keep going past any single login failure
Import-sqmDatabaseLogins `
-SqlInstance 'TestSQL' `
-Database 'Frontarena' `
-InputPath 'D:\Handover\Frontarena_Logins.sql' `
-DisablePolicy $false `
-ContinueOnErrorScheduled job: apply the newest Frontarena export from the handover directory, keep the three newest files
Import-sqmDatabaseLogins `
-SqlInstance 'TestSQL' `
-Database 'Frontarena' `
-InputPath 'D:\Handover' `
-KeepLatest 3