Adding files to a FileTable

In this recipe, we will programmatically add files to a FileTable.

Getting ready

Before you proceed with this recipe, you need to have a FileTable in your database. If you do not have one yet, you can follow the Adding a FileTable recipe in Chapter 6, Advanced Administration, to set one up. Alternatively, you can run the prep file B04525 - Ch09 - 03 - Adding Files to FileTable Prep.ps1 from the code bundle.

How to do it...

Let's take a look at the steps required to add multiple files to our FileTable using PowerShell and SMO:

  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" ...

Get SQL Server 2014 with PowerShell v5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.