Author Posts

August 30, 2018 at 4:15 pm

I have a question regarding this sentence..."SQL PowerShell 2016 starting with the SSMS 2016 now includes 6 cmdlets for working with SQL Agent objects."

I am trying to write a script to monitor SQL Agent job status on many servers. But I am pretty sure those new cmdlets will ONLY work when connecting to a server that has SQL 2016 installed, right? The servers on my network are 2016,2012, 2008.


August 30, 2018 at 4:58 pm

I have not used them, specifically because I have not SQL2K16 deployed, but I'd strongly suggest you take look at this module...


… and the authors article / site here:

scheduling powershell tasks with sql agent

August 30, 2018 at 6:46 pm

You are just performing a GET operation, so install SQL 2016 tools, import the module and see if you can connect to the SQL agent on all of the servers. But also a quick search nets:

New PowerShell Commands from the SQL Server Team!

with regards to the SQL Agent Cmdlets:

One of the best things about these cmdlets is that it makes failed jobs a whole lot easier to find. Note that SQL Server Management Studio 2016 does not have to be installed on the server — only your workstation. That's because the cmdlet is built on top of SMO which is available in all versions of SQL Server since 2000.

August 31, 2018 at 2:29 am

* dont need to install SQL Server tools, you can install the sqlserver or pwsh (PowerShell Core) module on it's own and get everything they have.

September 1, 2018 at 2:23 pm

Thanks for all the replies. dbatools seems to be a "must have" for a DBA. I wrote this simple script using Find-DbaAgentJob but it only seems to run against my SQL 2014 & 2016 SQL servers. I thought it might be the powershell version on the other servers but they are at v.4 Any ideas?

$allservers = "SVR2016","SVR2014","SVR2008"

$countOfErrors = ($allservers | Find-DbaAgentJob -failed -Since (Get-Date).AddDays(-1) | measure-object).Count

if($countOfErrors -gt 0) {

$allservers | Find-DbaAgentJob -failed -Since (Get-Date).AddDays(-1) | out-file c:\downloads\sqlAgentErrors.txt

Send-MailMessage -From "" -To ('') -Subject "failed SQL Agent job(s) in last day" -body "Open the attachment to see the failed SQL tasks within the last day." -attachments c:\downloads\sqlAgentErrors.txt -SmtpServer ""


September 1, 2018 at 2:35 pm

I verified powershell remoting is enabled on the servers where my script is not working.

#This works: 
get-DbaAgentJob  -SqlInstance FAUQxxx01
#This does not: 
Find-DbaAgentJob  -isfailed -SqlInstance FAUQxxx01 -Since (Get-Date).AddDays(-10)


September 1, 2018 at 3:23 pm

Are you geting any error ? or its just doesn't show anything from 2008 Server.

September 4, 2018 at 5:36 pm

no errors. It just doesn't return anything.