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

proxy2 class=

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 PowerShell MVP who has worked in IT for nearly 20 years, and currently serves as a Sr. Database Engineer in Belgium. Always an avid scripter, she attended the Monad session at Microsoft’s Professional Developers Conference in Los Angeles back in 2005 and has worked and played with PowerShell ever since. Chrissy is currently pursuing an MS in Systems Engineering at Regis University and helps maintain RealCajunRecipes.com in her spare time. She holds a number of certifications, including those relating to SQL Server, SuSE Linux, SharePoint and network security. She recently became co-lead of the SQL PASS PowerShell Virtual Chapter. You can follow her on Twitter at @cl.

Leave a Reply

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

*