I'm trying to invoke an inline powershell script from Task Scheduler to send an email when a particular event is triggered. I can't use the native 'Send an e-mail' action in the Task Scheduler action window because the SMTP server requires SSL and there's no way to specify this in the action window. So I'm looking to 'Start a program' and invoke something to send email but I want to avoid using 3rd party applications such as sendEmail if possible so was hoping to be able to invoke an inline powershell script similar to the following.
Setting the 'Program/script' field to powershell
and the arguments field to:
-Command "{Send-MailMessage -From "Name <name@domain.com>" -To "name@domain.com" -Subject "Test Subject" -Body "Test body at $(Get-Date -Format "dd/MM/yyyy")." -SmtpServer "smtp.domain.com" -UseSSL}"
This obviously doesn't work due to the nested quotes etc, so I've been trying different variations in command prompt, but I can't for the life of me figure out which characters I need to escape and how to escape them.
Any help would be much appreciated.