Start a SQL Agent Job with the .NET Framework from PowerShell

As of this writing, the most recent version of the SQLServer PowerShell module (which installs as part of SQL Server Management Studio) includes cmdlets for retrieving information about SQL agent jobs, but no cmdlets for starting them.


I recently ran into a situation where I needed to start a SQL agent job from PowerShell. The solution needed to be a tool that others could use who may or may not have the SQLServer module, SQLPS module or older SQL Server snap-in installed.

I decided to write a function to leverage the .NET Framework from PowerShell to start a SQL Server job:

The job returns a Boolean. True means it started successfully and false means it failed to start:


The Start-MrSqlAgentJob function shown in the previous code example can be downloaded from my SQL repository on GitHub.


Thanks to Rob Sewell for pointing out that Get-SqlAgentJob returns a SMO object which has a start method:


That means it can be used to start a SQL agent job:


It does require that SQL Server Management Studio 2016 be installed on the machine it’s being run from.


1 Comment

  1. SQLDBAwithTheBeard

    Good work

    (Get-SQLAgentJob -Instance Server -Name Jobnane).start() will work and stop too as GetSqlagentjob returns a smo object


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: