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

Please note that documentation and command names may be out of date while we work furiously towards 1.0


Upon being passed a list of potential backups files this command will scan the files, select those that contain SQL Server backup sets. It will then filter those files down to a set.

The function defaults to working on a remote instance. This means that all paths passed in must be relative to the remote instance. XpDirTree will be used to perform the file scans.

Various means can be used to pass in a list of files to be considered. The default is to non recursively scan the folder passed in.




Will use the Server1 instance to recursively read all backup files under c:\backups, and return a dbatool. BackupHistory object.

Get-DbaBackupInformation -SqlInstance Server1 -Path c:\backups\ -DirectoryRecurse

This allows you to move backup history across servers, or to preserve backuphistory even after the original server has been purged.

Get-DbaBackupInformation -SqlInstance Server1 -Path c:\backups\ -DirectoryRecurse -ExportPath c:\store\BackupHistory.xml
<#Copy the file c:\store\BackupHistory.xml to another machine via preferred technique, and the on 2nd machine:#>
Get-DbaBackupInformation -Import -Path c:\store\BackupHistory.xml | Restore-DbaDatabase -SqlInstance Server2 -TrustDbBackupHistory

In this example we gather backup information, export it to an xml file, and then pass it on through to Restore-DbaDatabase. This allows us to repeat the restore without having to scan all the backup files again

Get-DbaBackupInformation -SqlInstance Server1 -Path c:\backups\ -DirectoryRecurse -ExportPath c:\store\BackupHistory.xml -PassThru !
Restore-DbaDatabse -SqlInstance Server2 -TrustDbBackupHistory

This lets you keep a record of all backup history from the last month on hand to speed up refreshes.

Get-ChildItem c:\backups\ -recurse -files | Where {$.extension -in (‘.bak’,’.trn’) -and $.LastWriteTime -gt (get-date).AddMonths(-1)} | Get-DbaBackupInformation -SqlInstance Server1 -ExportPath c:\backupHistory.xml

Scan the unc folder \network\backups with Server1, and then scan the C:\backups folder on Server2 not using xp_dirtree, adding the results to the first set.

$Backups = Get-DbaBackupInformation -SqlInstance Server1 -Path \network\backupps
$Backups += Get-DbaBackupInformation -SqlInstance Server2 -NoXpDirTree -Path c:\backups


This command was created by Chrissy LeMaire. You can find Chrissy on Twitter.


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

Source Code

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

Related commands