Home Powershell Activity

Can you send a notification when a PowerShell Activity is run

Bryant_RichardsBryant_Richards Customer IT Monkey ✭
We are testing out the PowerShell Activity scripts and we wanted to know if there was a way of tracking if they run (a notification template). Is there a way to output the activity results into tickets history? We want to run a server reboot script using a PowerShell Activity and list the successful and unsuccessful ones in the activity's history or comments. Is that possible and if so how would we go about configuring it?

Answers

  • Jerry_VeldhuisJerry_Veldhuis Customer Advanced IT Monkey ✭✭✭
    Simple approach may be to send an email to the system and have the exchange connector add it as a comment to ticket. If you can catch when it fails, you could decide to send a different email to represent the failure. The subject line would just have to start with [WI].
  • Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Ninja IT Monkey ✭✭✭✭
    edited March 2017
    I haven't imported the MP yet, so I'm not 100% sure how it works, but does the activity not log itself in the action log when it runs? Doesn't it have a Status, which you could catch with a workflow?

    If not, then of the top of my head, there's a couple of different approaches to this: You could extend the WI with an custom field, to which you could write the output of the script inside the script itself, e.g.:
    get-scsmclass -name "System.WorkItem.ServiceRequest$" | get-scsmclassinstance) | where {$_.ID -eq $ID} | %{ $_.ScriptOutput = $result ; $_ } | update-scsmclassinstance
    You could also add an entry to the action log with the result with something like this: https://social.technet.microsoft.com/Forums/systemcenter/en-US/9456ff93-d301-401c-976e-e5b2be75024b

    In both cases, you could then catch the change with a workflow, where you match on Changed From not "Success" > Changed To "Success", and the same way for "Failed", which then sends the appropriate mail template to someone.
Sign In or Register to comment.