I’ve been meaning to get this finished and finally found some time. Its a function that will restart a single or multiple sql server agent services but only if no jobs are currently running.

Id like to say a big thank you to Chrissy LeMaire of DBA Tools fame for helping point me in the right direction for a few best practices, theirs still some work to do with it, mainly switch it to use SMO and add -WhatIf functionality, but its pretty usable as is, so thought i would share (I also find it interesting to see how code progresses so getting to see an early version my help some people or show some anti patterns to avoid!).

Very simple to use point in at the SQL instances you wish to restart the agent of and away you go! ie:

Restart-SQLAgent -SQLServer MyServer

it works with multiple servers so you can also use

Restart-SQLAgent -SQLServer MyServer, MyServer2, MyServer3

Output looks like below

Capture.PNG

Restart-SQLAgent GitHub Link

Edit 1

Updated to use SMO, and fixed named instances usage

Edit 15… .

Support for -WhatIf and -confirm, cleaned up the output for when an agent job is running so it now looks like:

Capture03.PNG

 

 

 

Advertisements