dbatools is a free PowerShell module with over 180 SQL Server administration, best practice and migration commands included.


Get-DbaRestoreHistory

Returns restore history details for databases on a SQL Server. By default, this command will return the server name, database, username, restore type, and date.

Specifying -Details will add From and To fields. Using -Force will give super detailed information on the restore.

Thanks to Kenneth Fisher for the idea.

Screenshots

get-dbarestorehistory10

get-dbarestorehistory11

get-dbarestorehistory7

Examples

To return server name, database, username, restore type, date, from file and to files for all restored databases on sqlserver2014a.

Get-DbaRestoreHistory -SqlServer sqlserver2014a

To return restore information only for databases db1 and db2 on sqlserve2014a since July 1, 2016 at 10:47 AM.

Get-DbaRestoreHistory -SqlServer sqlserver2014a -Databases db1, db2 -Since ‘7/1/2016 10:47:00’

To show tons (89 columns) of detailed information about the restores for all databases except db1 on sqlserver2014a and sql2016.

Get-DbaRestoreHistory -SqlServer sqlserver2014a, sql2016 -Detailed -Exclude db1

To show simplified output (remove from and to), return information only for AdventureWorks2014 and pubs, and make the output pretty

Get-DbaRestoreHistory -SqlServer sql2014 -Databases AdventureWorks2014, pubs -Simple | Format-Table

To return database restore information for every database on every server listed in the Central Management Server on sql2016

Get-SqlRegisteredServerName -SqlServer sql2016 | Get-DbaRestoreHistory

Additional Screenshots

get-dbarestorehistory8

References

When was the last time your SQL Server database was restored – Thomas LaRock, mssqltips.com

Get-Help

From PowerShell, execute Get-Help Get-DbaRestoreHistory -Detailed for more information on this function.

Source Code

Want to see the source code? View Get-DbaRestoreHistory.ps1 on GitHub
 

Related commands