Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By : Donabel Santos
Book Image

SQL Server 2014 with PowerShell v5 Cookbook

By: Donabel Santos

Overview of this book

Table of Contents (21 chapters)
SQL Server 2014 with PowerShell v5 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Listing backup header and FileList information


In this recipe, we will see how to list backup header information from a backup file.

Getting ready

We need to list the existing backup's header information.

Note

If you do not have any backups in your system yet, you can go back to any of this chapter's Backup recipes prior to performing this recipe.

How to do it...

To list the header information, follow these steps:

  1. Open PowerShell ISE as administrator.

  2. Import the SQLPS module as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
  3. Add the following script and run:

    $instanceName = "localhost"
    $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
    
    #replace this with your backup file
    $backupfile = "AdventureWorks2014.bak"
    
    #replace this with your backup directory
    $backupdir = $server.Settings.BackupDirectory
    
    #get full path
    $backupfilepath = Join-Path $backupdir $backupfile
    
    #SMO restore object will allow us to
    #investigate contents...