Commands / Export-sqmServerConfiguration
Export-sqmServerConfiguration
Configuration sqmSQLTool v1.8.2+ · Export ✓ Snapshot / Rollback
Captures a comprehensive configuration snapshot of a SQL Server instance and saves it as a timestamped JSON file. Designed for pre-change documentation, baseline comparison, and rollback support.

Captured categories: SpConfigure (all sp_configure values with run/config/min/max), InstanceProperties (edition, version, collation, login mode, default paths, HA flags), Services (SQL Server / Agent / SSRS / SSIS state, start mode, service account), TempDb (file count, sizes, growth settings), DatabaseMail (profile names), LinkedServers. Optionally Databases overview via -IncludeDatabases.

Each category that fails is logged as a warning; the remaining categories are still captured (Status = 'Partial' is implicit from the categories list). The outer catch converts a total connection failure to Write-Error or throw, depending on -EnableException.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestringOptional$env:COMPUTERNAMETarget SQL Server instance. Not pipeline-capable.
-SqlCredentialPSCredentialOptionalCredentials for the SQL connection.
-OutputPathstringOptional$env:ProgramData\sqmSQLTool\SnapshotsDirectory for the JSON file. Created if missing.
-LabelstringOptionalDescriptive label stored in JSON metadata (e.g. "before MaxMemory change").
-IncludeDatabasesswitchSwitch$falseAlso capture database-level overview (slower; adds a Databases category).
-EnableExceptionswitchSwitch$falseRe-throw on total failure instead of Write-Error. Per-category errors are always warnings only.

Output

PropertyTypeDescription
SnapshotPathstringFull path to the saved JSON file.
TimestampstringISO 8601 timestamp of the export.
ItemCountintTotal settings captured across all categories.
Categoriesstring[]List of successfully captured category names.
Statusstring'Success' — or check Categories for omissions if a category errored.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES -SqlInstance default ($env:COMPUTERNAME) | Ensure OutputPath OutputPath missing → New-Item -Force | fail → log ERROR + return $null (or throw) Connect-DbaInstance -ErrorAction Stop fail → outer catch → Write-Error or throw (EnableException) Collect categories — each wrapped in its own try/catch (fail = log WARN, skip category) 1 SpConfigure — server.Configuration loop → RunValue, ConfigValue, IsDynamic … 2 InstanceProperties (SMO) — Edition, Version, Collation, Paths, IsClustered, IsHadrEnabled … 3 Services — Get-DbaService → ServiceName, State, StartMode, ServiceAccount … 4 TempDb — Get-DbaDbFile -Database tempdb → file count, sizes, growth … 5 DatabaseMail — Get-DbaDbMailProfile → profile names, IsPublic, IsDefault 6 LinkedServers — Get-DbaLinkedServer → Name, DataSource, Provider … -IncludeDatabases switch set? YES Get-DbaDatabase → add Databases NO Build snapshot object → ConvertTo-Json -Depth 10 Metadata: ExportDate, ExportedBy, ComputerName, InstanceName, Label, Categories Filename: <Server>_<Instance>_<yyyyMMdd_HHmmss>.json → Set-Content UTF-8 Return [PSCustomObject] Status='Success' SnapshotPath, Timestamp (ISO 8601), ItemCount, Categories[] catch (total fail): Write-Error or throw DONE

Examples

Snapshot before a configuration change (with descriptive label)
$snap = Export-sqmServerConfiguration -SqlInstance "SQL01" -Label "before MaxMemory change"
Write-Host "Snapshot: $($snap.SnapshotPath)"
Full export including database overview to a custom path
Export-sqmServerConfiguration -SqlInstance "SQL01" `
    -OutputPath "C:\Backups\SQLSnapshots" `
    -IncludeDatabases `
    -Label "production-baseline"