< Back

Get-DbaDbRestoreHistory

Mon Jan 13, 2020 10:53 am

NAME Get-DbaDbRestoreHistory



SYNOPSIS

Returns restore history details for databases on a SQL Server.





SYNTAX

Get-DbaDbRestoreHistory [-SqlInstance] <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>

[[-SqlCredential] <Pscredential>] [[-Database] <System.Object[]>] [[-ExcludeDatabase] <System.Object[]>] [[-Since]

<Datetime>] [-Force <Switch>] [-Last <Switch>] [-EnableException <Switch>] [<CommonParameters>]





DESCRIPTION

By default, this command will return the server name, database, username, restore type, date, from file and to

files.



Thanks to

https://www.mssqltips.com/SqlInstanceti ... -restored/ for

the query and https://sqlstudies.com/2016/07/27/when- ... -restored/ for the idea.





PARAMETERS

-Database [<System.Object[]>]

Specifies the database(s) to process. Options for this list are auto-populated from the server. If

unspecified, all databases will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.

This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables

advanced scripting.

Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own

try/catch.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-ExcludeDatabase [<System.Object[]>]

Specifies the database(s) to exclude from processing. Options for this list are auto-populated from the server.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

Deprecated.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Last [<Switch>]

If this switch is enabled, the last restore action performed on each database is returned.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Since [<Datetime>]

Specifies a datetime to use as the starting point for searching backup history.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).



Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -

Integrated are all supported.



For MFA support, please use Connect-DbaInstance.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

Specifies the SQL Server instance(s) to operate on. Requires SQL Server 2005 or higher.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: DisasterRecovery, Backup, Restore

Author: Chrissy LeMaire (@cl), netnerds.net



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Get-DbaDbRestoreHistory -SqlInstance sql2016



Returns server name, database, username, restore type, date for all restored databases on sql2016.

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Get-DbaDbRestoreHistory -SqlInstance sql2016 -Database db1, db2 -Since '2016-07-01 10:47:00'



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

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Get-DbaDbRestoreHistory -SqlInstance sql2014, sql2016 -Exclude db1



Returns restore information for all databases except db1 on sql2014 and sql2016.

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>$cred = Get-Credential sqladmin



PS C:\\> Get-DbaDbRestoreHistory -SqlInstance sql2014 -Database AdventureWorks2014, pubs -SqlCredential $cred |

Format-Table



Returns database restore information for AdventureWorks2014 and pubs database on sql2014, connects using SQL

Authentication via sqladmin account. Formats the data as a table.

-------------------------- EXAMPLE 5 --------------------------



PS C:\\>Get-DbaRegServer -SqlInstance sql2016 | Get-DbaDbRestoreHistory



Returns database restore information for every database on every server listed in the Central Management Server on

sql2016.



RELATED LINKS

https://dbatools.io/Get-DbaDbRestoreHistory