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

Adding a FileTable


In this recipe, we will create a FileTable.

Getting ready

Before you can use a FileTable, the FileStream feature needs to be first enabled on your instance. If you haven't already enabled it, you can follow the Enabling FileStream recipe to enable it.

In addition, you should also have a Filestream filegroup. You can follow the Setting up a FileStream filegroup recipe to prepare this recipe.

How to do it...

Let's take a look at the steps to create a FileTable using SMO and PowerShell:

  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 script and run it:

    #filestream enabled database
    $databaseName = "FileStreamDB"
    $db = $server.Databases[$databaseName]
    
    #get handle to filestream filegroup
    $filegroupName = "FilestreamData...