Adding a SQL Server operator

In this recipe, we'll see how you can create a SQL Server operator using SMO and PowerShell.

Getting ready

For this recipe, we will create an operator with the following settings:

Setting operator

Value

Name

tstark

E-mail

tstark@queryworks.local

If you do not have this account set up in your system, you can substitute this with another available account in your environment that has an e-mail address. To set up an operator, you must be a sysadmin for your instance.

How to do it...

To create an operator, follow these steps:

  1. Open PowerShell ISE as administrator.
  2. Import the SQLPS module and create a new SMO Server object:
    #import SQL Server module Import-Module SQLPS -DisableNameChecking #replace this with your instance ...

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.