0 votes

Hello, I've created a custom command to run a script which will send an email alert if the script encounters an error. I have the command set to run as a scheduled task.

How would I dynamically display the name of the custom command and scheduled task in the email alert?

This is an example of what I'd want to show in the email alert from the Powershell script that sends it:

Custom Command Name: Task Name: Time: Error Message:

Thank you.

ago by (320 points)

1 Answer

0 votes
ago by (284k points)
selected ago by
Best answer

Hello,

Unfortunately, there is no possibility to obtain the custom command name in the script. It can only be set as plain text. As for the scheduled task, you can use value reference %initiator%.

0

Support, thank you for the response. Using the %initiator% value reference will work for me. For anyone else wanting to do something similar this is how I approached it using a try/catch block:

$Now = "%datetime:format[MM/dd/yyyy hh:mm tt]%"
$TaskName = "%initiator%"
$Context.LogMessage($_.Exception.Message, "Warning")
$SMTPServer = "MODIFY ME"
$From = "MODIFY ME"
$To = "MODIFY ME"
$Subject = "Adaxes - Error Occurred When Running Scheduled Task"
$Body = "
Date/time: $Now <br>
Task: $TaskName <br>
Error: ($_.Exception.Message)"
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -BodyAsHtml -SmtpServer $SMTPServer 
0

Hello,

Thank you for the confirmation. We do not see any try/catch blocks in your script, but it should work just fine. Also, you can use a built-in method $Context.SendMail for email delivery. In this case, the mail settings of Adaxes service will be used and there will be no need to specify the SMTP server.

Related questions

0 votes
1 answer

Using the powershell module, I know how to create a scheduled task, and also how to bind to a scheduled task that is already known. I also have used code to try creating ... same time as another. These are all one-time tasks and will be removed once executed.

asked Jan 19 by aweight (40 points)
0 votes
1 answer

Similar to Powershell's "whatif"? I'd like to enable this scheduled task - But would like to confirm who will actually be affected before enabling this. Is there at least ... objects in the console log? I could run that before adding the 'modify' actions back.

asked Jun 25 by msinger (210 points)
0 votes
1 answer

I want to create a scheduled task to disable a user if he is inactive for 30days, the task must check inacivity o AD and Azure.

asked May 16 by johanpr (120 points)
0 votes
1 answer

So I have custom forms for onboarding / offboarding users. We sometimes know 2-3 weeks in advance so I would like to add the ability to schedule these for the future. I ... to take all the data that was inputed and then process the request on the given date?

asked Aug 4, 2023 by thatcher (120 points)
0 votes
1 answer

Hello! how do i manage do get adaxes to remove all groups from the user after one month? We have a Business Rule where you can add an end of Date when the Account ... value field the powershell script works but not with the +1 Month. Thanks for your help!

asked Jun 14, 2023 by eww ag (140 points)
3,490 questions
3,183 answers
8,116 comments
547,182 users