THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Buck Woody

Carpe Datum!

Start a SQL Server Agent Job using the SQL Server PowerShell Provider

Whew!  That’s a mouthfull. Anyway, I thought I would share part of a script I wrote today to help automate (more) from PowerShell. This assumes a few things: that you’re doing this from the SQL Server 2008 PowerShell provider (not just good old regular PowerShell) and that you change the HAL9000 and SQL2K8 parts with your server name and your Instance name. Oh, and the Jobs I start are called “Test” and then something else. That’s the Test* part. You can use a specific name and drop the * or use your own naming convention.

Script Disclaimer, for people who need to be told this sort of thing:

Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.


# Start a Job named Test in the SQL Server 2008 PowrShell Provider

DIR SQLSERVER:\SQL\HAL9000\SQL2K8\JobServer\Jobs\Test* | % {$_.Start()}

Published Wednesday, February 10, 2010 6:13 AM by BuckWoody



AllenMWhite said:

One note, Buck, is that it's generally considered best practice to use the actual cmdlet name in scripts, so I'd replace the 'DIR' with 'Get-ChildItem' for clarity.

February 10, 2010 1:36 PM

BuckWoody said:

Allen - true that. but I like DIR. And always will.

February 10, 2010 2:03 PM

AllenMWhite said:

Well, Buck, you're a Windows kinda guy.  I prefer ls, myself.  It's only two letters, and one for each hand, so it's more efficient to type than dir.

February 10, 2010 2:58 PM

BuckWoody said:

Ah - but you're brighter than me, young man. I'm just an old sysadmin.

Thanks again for the comments. Keep em coming.

February 10, 2010 4:58 PM

Michiel Wories said:

Very nice Buck. This really shows off the power of a well implemented provider.

February 11, 2010 4:00 PM
New Comments to this post are disabled

About BuckWoody

This Blog


Privacy Statement