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 database snapshots


In this recipe, we will list the database snapshots that are available in your instance.

Getting ready

You may choose to create a test snapshot if the instance that you are using does not have any database snapshots. You can use the following T-SQL script, or you can choose to perform the Creating a database snapshot recipe first before we proceed with this recipe.

How to do it...

The following steps walk you through listing database snapshots:

  1. Open PowerShell ISE as an administrator.

  2. Import the SQLPS module as follows:

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

    $instanceName = "localhost"
    $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
    
    $server.Databases |
    Where-Object IsDatabaseSnapshot -eq $true

How it works...

A database snapshot is a static, read-only view of a source database at the time its snapshot was created. Database snapshots are initially created...