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


Read-DbaBackupHeader

Reads and displays detailed information about a SQL Server backup

Reads full, differential and transaction log backups. An online SQL Server is required to parse the backup files and the path specified must be relative to that SQL Server.

Screenshots

Examples

To log into sql2016 using Windows authentication and reads the local file on sql2016, S:\backups\mydb\mydb.bak.

If you are running this command on a workstation and connecting remotely, remember that sql2016 cannot access files on your own workstation.

Read-DbaBackupHeader -SqlServer sql2016 -Path S:\backups\mydb\mydb.bak

To log into sql2016 and reads two backup files – mydb.bak and otherdb.bak. The SQL Server service account must have rights to read this file.

Read-DbaBackupHeader -SqlServer sql2016 -Path \nas\sql\backups\mydb\mydb.bak, \nas\sql\backups\otherdb\otherdb.bak

To log into the local workstation (or computer) and shows simplified output about C:\temp\myfile.bak. The SQL Server service account must have rights to read this file.

Read-DbaBackupHeader -SqlServer . -Path C:\temp\myfile.bak -Simple

To display detailed information about each of the datafiles contained in the backupset.

$backupinfo = Read-DbaBackupHeader -SqlServer . -Path C:\temp\myfile.bak
$backupinfo.FileList

To return detailed information about each of the datafiles contained in the backupset.

Read-DbaBackupHeader -SqlServer . -Path C:\temp\myfile.bak -FileList

Gets a list of all .bak files on the \nas\sql share and reads the headers using the server named “sql2016”. This means that the server, sql2016, must have read access to the \nas\sql share.

Get-ChildItem \nas\sql*.bak | Read-DbaBackupHeader -SqlServer sql2016

From PowerShell, execute   Get-Help Read-DbaBackupHeader -Detailed   for more information on this function. Want to see the source code? See it on GitHub