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

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

[email protected]

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 name
    $instanceName = "localhost"
    $server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList $instanceName

    Add the following script and run:

    $jobserver     = $server.JobServer
    $operatorName  = "tstark"
    $operatorEmail =...