Commands / Export-sqmDatabaseDocumentation
Export-sqmDatabaseDocumentation
Configuration sqmSQLTool v1.8.2+ · Export ✓ -WhatIf supported  🛠 Pipeline
Creates self-contained HTML reports and CSV files documenting every database on one or more SQL Server instances.

For each database the report contains: general properties (recovery model, collation, owner, compatibility level, ReadOnly/AutoClose/AutoShrink), data and log size, last backup times (Full / Diff / Log), last DBCC CHECKDB date, VLF count (SQL Server 2016+), optional filegroup/file details, object summary (tables, views, SPs, functions, triggers, synonyms), and database users.

Backup info, CHECKDB, and VLF data are pre-loaded with a single query per instance (not per database). Output files are additionally copied to the module-configured CentralPath via Copy-sqmToCentralPath.

Parameters

ParameterTypeRequiredDefaultNotes
-SqlInstancestring[]Optional$env:COMPUTERNAMEOne or more instances. Pipeline-capable.
-SqlCredentialPSCredentialOptionalCredentials for all SQL connections.
-Databasestring[]Optional@() = all user DBsLimit to specific databases. Wildcards allowed (Sales*).
-IncludeSystemDatabasesswitchSwitch$falseInclude master, model, msdb. tempdb is always excluded.
-IncludeFileDetailsboolOptional$trueInclude filegroup/file section in the HTML report.
-IncludeUsersboolOptional$trueInclude database users section.
-IncludeObjectSummaryboolOptional$trueInclude object counts (tables, views, SPs, functions, triggers, synonyms).
-OutputPathstringOptionalGet-sqmDefaultOutputPathOutput directory. Created if missing.
-ContinueOnErrorswitchSwitch$falseContinue to the next database or instance on error instead of stopping.
-EnableExceptionswitchSwitch$falseRe-throw exceptions (overrides -ContinueOnError).
-NoOpenswitchSwitch$falseDo not auto-open the HTML report after creation.
-WhatIf / -ConfirmswitchOptionalShouldProcess (ConfirmImpact: None) guards the file-write step.

Execution Flow

START dbatools installed? NO throw: dbatools not found YES -SqlInstance provided? NO → Default: $env:COMPUTERNAME foreach $instance in $SqlInstance Connect-DbaInstance → Get-DbaDatabase Filter: exclude tempdb | system DBs (unless -IncludeSystemDatabases) | apply -Database wildcard filter DBs found after filter? NO add Warning result continue YES Pre-load lookup tables (one query per topic per instance) 1) Backup times → msdb.dbo.backupset (Full/Diff/Log) 2) CHECKDB → DATABASEPROPERTYEX(name,'LastGoodCheckDbTime') 3) VLF count → sys.dm_db_log_info (SQL 2016+ only; skipped on error) Build HTML: header + table of contents (sorted by DB name) internal helpers: _HtmlHead, _HtmlEncode, _HtmlTable (no external CSS) foreach $db in $filteredDbs (sorted by Name) Look up backup times + CHECKDB age + VLF count from pre-loaded lookups Calc sizes: data (FileGroups.Files) + log (LogFiles) | Set status class (ok/warn/crit) Append HTML: Props | Backups | CHECKDB | Files* | Object summary* | Users* (*if -IncludeFileDetails / -IncludeObjectSummary / -IncludeUsers) | add CSV row catch per-DB: log error + append error block in HTML (continue if -ContinueOnError) ShouldProcess? (ConfirmImpact: None) NO WhatIf: log files = $null YES Ensure OutputPath → Write HTML + CSV Copy-sqmToCentralPath | Open HTML (unless -NoOpen) Add [PSCustomObject] to $allResults SqlInstance, DatabaseCount, HtmlFile, CsvFile, Status, Timestamp Return $allResults [PSCustomObject[]] — one entry per instance DONE

Examples

Document all user databases on the local instance
Export-sqmDatabaseDocumentation
Document specific databases on SQL01 to a custom path
Export-sqmDatabaseDocumentation -SqlInstance "SQL01" -Database "SalesDB","HRApp" -OutputPath "D:\Reports"
Multiple instances via pipeline, continue on error, include system databases
"SQL01","SQL02","SQL03" | Export-sqmDatabaseDocumentation -IncludeSystemDatabases -ContinueOnError -NoOpen