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
About the Author
About the Reviewers

Creating a database snapshot

In this recipe, we will create a database snapshot.

Getting ready

SQL Server database snapshots require either the SQL Server Developer or Enterprise edition. You can also use the Evaluation edition, which is similar to the Enterprise edition.

We will use the script called B04525 - Ch06 - 04 - Creating a Database Snapshot - Prep.ps1 to create a sample database that we will base our snapshot on. The database created in this script will have multiple Filegroups and data files.

Alternatively, you can choose a source database that you would like to serve as the base of your snapshot.

How to do it...

Let's take a look at the steps to create a database snapshot:

  1. Open PowerShell ISE as an administrator.

  2. Import the SQLPS module and create a new SMO Server object as follows:

    #import SQL Server module
    Import-Module SQLPS -DisableNameChecking
    $instanceName = "localhost"
    $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName
  3. Add the following...