Get-sqmDatabaseRestoreHistory
Backup & Restore
sqmSQLTool v1.8.2+ · Get
✓ -WhatIf supported
Why this exists: a raw
Get-DbaDbRestoreHistory -Last only returns rows for databases that actually appear in msdb.dbo.restorehistory, a database that was never restored simply never shows up. That's fine for "what happened," but useless for "did the restore I expected actually run", or for compliance/audit questions like "which of our databases have never had a restore tested." This command cross-references the full database list on the instance so the answer includes every database, not just the ones with history.Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string[] | Optional | $env:COMPUTERNAME | Pipeline-capable. Multiple instances supported. |
| -SqlCredential | PSCredential | Optional | , | |
| -ExcludeDatabase | string[] | Optional | , | Wildcards allowed. tempdb always excluded. |
| -IncludeSystemDatabases | switch | Switch | $false | Include master/model/msdb. tempdb always excluded. |
| -OutputPath | string | Optional | <OutputPath config>\DatabaseRestoreHistory | Created automatically if it does not exist. |
| -ContinueOnError | switch | Switch | $false | Continue to next instance on error instead of throwing. |
| -EnableException | switch | Switch | $false | Throw exceptions immediately (overrides ContinueOnError). |
| -NoOpen | switch | Switch | $false | Do not automatically open the generated report after creation. |
Execution Flow
Examples
Restore history, local instance, default filters
Get-sqmDatabaseRestoreHistory
Multiple instances, include system databases
Get-sqmDatabaseRestoreHistory -SqlInstance "SQL01","SQL02" -IncludeSystemDatabases -OutputPath "D:\Reports"
Exclude a set of scratch/test databases
Get-sqmDatabaseRestoreHistory -SqlInstance "SQL01" -ExcludeDatabase "Test_*","*_scratch"
Find databases that have never been restored (e.g. for a restore-test audit)
(Get-sqmDatabaseRestoreHistory -SqlInstance "SQL01").DetailRows | Where-Object { -not $_.LastRestoreDate }Pipeline, check all instances from OU
Get-sqmServersFromOU -OUPath "OU=SQL,DC=corp,DC=local" | Get-sqmDatabaseRestoreHistory -ContinueOnError