SQL Agent

This category page is part of a series of Professional PowerShell SMO Recipes. You can find an index of all recipes on the main SMO Recipes page, and if you want to learn more about each recipe and see some sample screenshots, click on its category page.

These scripts were created and tested on Windows 8.1 with PowerShell v4 and SQL Server 2014, though most recipes should work with earlier versions of SQL Server. PowerShell v3 and above is required for many of the recipes. If you have a recipe request, leave a comment and I'll see what I can do. This cookbook will be continuously built, as I work more with SMO.

Recipe Categories

SQL Agent

I’m starting a new project that uses SQL Agent extensively, so this section is likely to grow. By the way, if you aren’t familiar with SQL Server credentials and Agent Proxies, consider reading up on it. You may find this feature useful.

Is SQL Server Agent running?

Find failed jobs

Create Scheduled T-SQL based SQL Server Agent Job

Create credential, proxy account, and job to run local PowerShell scripts

Want to run PowerShell scripts within SQL Agent but not use SQLPS? This script creates a credential (which can be skipped if the SQL Agent account has necessary access), sets up a CmdExec proxy, then creates a job that uses the new credential. The job has one step which executes a script located on the SQL Server at C:\Scripts\Test-Example.ps1

If the account you’re adding does not have a login on the server, it will be added. If the account you’re adding does not have sysadmin access, it will be added to the Proxy Principal list.

Want to see more? You can find an index of all recipes on SMO Recipes Index Page page or click on any specific category at the top of this page.

Chrissy is a Cloud and Datacenter Management & Data Platform MVP who has worked in IT for over 20 years. She is the creator of the popular SQL PowerShell module dbatools, holds a master's degree in Systems Engineering and is coauthor of Learn dbatools in a Month of Lunches. Chrissy is certified in SQL Server, Linux, SharePoint and network security. You can follow her on Twitter at @cl.

Leave a Reply

Your email address will not be published. Required fields are marked *