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:
- Open PowerShell ISE as an administrator.
- Import the
SQLPS
module as follows:#import SQL Server module Import-Module SQLPS -DisableNameChecking
- 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...