Creating a SQL Server Instance Object

Most of what you will need to do in SQL Server will require a connection to an instance. One way to do this is by creating an instance object via SMO.

Getting ready

Open up your PowerShell console, PowerShell ISE, or your favorite PowerShell editor.

You will need to note what your instance name is. If you have a default instance, you can use your machine name. If you have a named instance, the format will be <machine name>\<instance name>.

How to do it...

If you are connecting to your instance using Windows authentication and using your current Windows login, the steps are as follows:

  1. Import the SQLPS module:
    #import SQLPS module
    Import-Module SQLPS –DisableNameChecking
    $VerbosePreference = "SilentlyContinue"
  2. Store ...

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.