In this recipe, we will create a new LocalDB instance.
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.
These are the steps to create a new LocalDB instance:
Open PowerShell ISE as an administrator.
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
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...