In this recipe, we'll see how you can create a SQL Server operator using SMO and PowerShell.
For this recipe, we will create an operator with the following settings:
Setting operator |
Value |
---|---|
Name |
|
|
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.
To create an operator, follow these steps:
Open PowerShell ISE as administrator.
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 =...