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.
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:
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.
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 "sextonk@fauqhealth.org" -To ('sextonk@fauqhealth.org') -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 "myMailServer.fauquierhospital.org"
}