Creating a SQL Server Job

In this recipe, we will create a simple SQL Server job programmatically.

Getting ready

We are going to create a simple job called Test Job and set up tstark as our operator. We added tstark as an operator in the recipe Adding a SQL Server operator. If you don't have tstark, choose another SQL Server operator that's available in your instance.

How to do it...

Let's look at the steps required to create a SQL Server Job programmatically:

  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 ...

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.