O'Reilly logo

SQL Server 2014 with PowerShell v5 Cookbook by Donabel Santos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required