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

Creating a new LocalDB instance


In this recipe, we will create a new LocalDB instance.

Getting ready

You need to make sure that LocalDB is installed. You can download LocalDB with SQL Server Express from MSDN downloads at https://www.microsoft.com/en-ca/download/details.aspx?id=42299.

How to do it...

These are the steps to create a new LocalDB instance:

  1. Open PowerShell ISE as an administrator.

  2. Add the following script and run it:

    #create new LocalDB instance
    $localDBInstance = "NewLocalDB"
    $command = "SQLLocalDB create `"$($localDBInstance)`""
    
    #execute the command
    Invoke-Expression $command
    
    #confirm by listing all instances
    $command = "SQLLocalDB i"
    Invoke-Expression $command

How it works...

You can also connect to and manage LocalDB using an executable utility called SQLLocalDB that comes with the installation. Since this method uses the executable and not SMO, you can use Invoke-Expression cmdlet and pass SQLLocalDB as a parameter. To learn more about the operations and parameters available in...