Issue with powershell command for service down

  • Hi All,

    I have migrated (sort of) from the SQL areas :).

    So I am trying to get an email sent when the MSSQLSERVERAGENT service goes down.

    I have this script:

    -Command 'Send-MailMessage -To k@email.co.uk -Subject \”SQL Agent Stopped on Dev - test only\” -Body \"Please look into the issue; Scheduled Jobs will not run if the SQL Server Agent Service remains stopped.\" -SmtpServer mailhost.co.uk -Port 25 -From k@email.co.uk'

    and also set it up as per these instructions for the rest:

    http://sqlish.com/alert-when-sql-server-agent-service-stops-or-fails/

    Any pointers at all? No errors in the logs, nothing and obviously no emails.

    Thanks for any help in advance.

  • That looks like an incomplete command. Do you have Powershell as the program being run? Are you use this is in the path for the system?

    I'd do something like
    "test" | Out-File "e:\Documents\test.txt"
    to test that I get a file when the service stops.

  • can you telnet to port 25 on your mail server from this host?

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle

  • Yep, done the Telnet test that's fine and the port is accessible.

    I do have PowerShell as the command and then I also added the path to the PowerShell.exe but neither one works.

    Steve, forgive my ignorance literally put that in as is?

    I should have also said that my command works in PowerShell itself and not in the services command area. Which is REALLY odd.

  • My suspicion is that there is one of two things happening.

    1. The powershell exe isn't firing for the account in services (not in path, or something else)
    2. The account doesn't have  rights or access to the mail server.

    Change the path in my command (you might not have an e: drive) and beware that many modern OSes don't allow writing to the root. Really, this is just to test that you are actually executing PoSh when the service stops.

  • Steve Jones - SSC Editor - Tuesday, April 18, 2017 10:28 AM

    My suspicion is that there is one of two things happening.

    1. The powershell exe isn't firing for the account in services (not in path, or something else)
    2. The account doesn't have  rights or access to the mail server.

    Change the path in my command (you might not have an e: drive) and beware that many modern OSes don't allow writing to the root. Really, this is just to test that you are actually executing PoSh when the service stops.

    I think I concur with your permission suspicion, we have now thankfully found another solution with Zabbix notifying us. So thankfully we will get notified at least.

    Thanks all for the sanity check/help

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply