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.

by (320 points)

1 Answer

0 votes
by (301k points)
selected 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, 2024 by aweight (60 points)
0 votes
1 answer

Hi, I have a lot of custom PowerShell scripts running and I am wondering, if its possible somehow to get the name of the PS Script the line of the execution of a code ... occurs and send directly the action, maybe path in Adaxes and line number of the script.

asked Oct 7, 2024 by wintec01 (1.8k points)
0 votes
1 answer

Is there a way to get the name of the user who approved a request and supply that to a step inside of a custom command? For example, HR submits a status change for an employee. ... and pass it as a param in a custom command that is called in one of the steps?

asked May 12, 2021 by davfount90 (20 points)
0 votes
1 answer

Hello, i have a custom command which sets the oof-message for the selected user. in this custom command i have a parameter "param-vertretung" (ad-object picker). Now i want to ... and email of the stand-in in the oof-message. Can you help me with that? Thanks

asked Nov 13, 2020 by lohnag (160 points)
3,677 questions
3,361 answers
8,494 comments
549,333 users