Notification on all unassigned incidents

I saw a question in the forum today about notification on unassigned incidents. This is difficult to do from the console because there is no support for subscribing to the absence of a relationship. If you want notification on all unassigned incidents that are older then X hours you could instead use a custom script. The script could then be triggered by a workflow in Service Manager. In this post I can build a simple script that I will add to a workflow. The script will run every hour and see if there are any unassigned incidents that are older then 2 hours.

  1. Open Service Manager Authoring Tool and create a new management pack, in my case Contoso.Unassigned
  2. Right-click Workflows and create a new workflow
  3. In the Create Workflow Wizard, General, input a name, for example ContosoUnassignedIncidents
  4. In the Create Workflow Wizard, Trigger Condition, select Run at a scheduled time or at…
  5. In the Create Workflow Wizard, Trigger Criteria, select Other interval and 1 Hours
  6. In the Workflow window, from the toolbox, drag and drop the Windows PowerShell Script
  7. In the properties of the script activity, paste the following script into the script body field

    $smtphost=”LUDSRV206″
    $to=”kurt@contoso.local”
    $from=”svc-wf-ludsrv204@contoso.local”

    function Send-Mail
    {
    param($From,$To,$Subject,$Body)
    $smtp = new-object system.net.mail.smtpClient($smtphost)
    $mail = new-object System.Net.Mail.MailMessage
    $mail.from= $From
    $mail.to.add($To)
    $mail.subject= $Subject
    $mail.body= $Body
    $mail.isbodyhtml=$true
    $smtp.send($mail)
    }

    Import-Module SMLets
    $BeforeDate = (get-date).AddHours(-2).ToString(“yyy-MM-dd HH:mm:ss”)
    $getIncidents = Get-SCSMIncident -Status “Active” -CreatedBefore $BeforeDate | where { $_.AssignedTo -eq $NULL } | select ID, Title, AffectedUser

    if ($getIncidents.count -gt 0) {

    $subject= “Unassigned incidents in Service Manager, total of ” + $getIncidents.count
    $body=$getIncidents|convertto-html
    Send-Mail $from $to $subject $body

    }

    Remove-Module SMLets

  8. Modify the following parameters to fit your environment
    • $smtphost = hostname of your mailserver
    • $to = the e-mail address that will recive the e-mail
    • $from = the e-mail address that the script will use to send the e-mail
    • $subject = the subject in the e-mail
  9. Save your management pack
  10. Copy the ContosoUnassignedIncidents.dll to the C:\Program Files\Microsoft System Center\Service Manager 2010 directory on your Management Server
  11. Import your management pack into Service Manager

After a hour the e-mail address in your $TO parameter (in the script) could get a e-mail looking like this

In this e-mail we can see all incidents older then two hours that don’t have anyone in “assigned to”. To verify that your workflow is running you can look in the Workflows/Status view in the Administration workspace. A nice extension of this soultion could be to control notification from the console and not in the script. Also adding support for different notification based on incident area and category. That is something for the feature 🙂 Also, please not that my scrip needs the Service Manager cmdlets, more info about them here.

16 thoughts on “Notification on all unassigned incidents

  1. Could any of you guys enlighten me on how to get a hand on this ContosoUnassignedIncidents.dll ?

  2. Hi, if I would build that today I would put it in Orchestrator or Opalis and use a schedule in there instead. I guess you could build it in Service Manager too, but if I had Orchestrator or Opalis around I would put it there as I have more knowledge in that product today.

  3. Hi Anders, I manually test the script and it works just fine. When I copy the .dll and import the MP, I dont receive any email. The workflow succeed every 3 minutes.

    I only change: $BeforeDate = (get-date).AddMinutes(-10).ToString(“yyy-MM-dd HH:mm:ss”)

    Any idea why I am not getting any email?

  4. Hi Anders,

    what i want to accomplish is that, i want all the incidents created to be assigned to a group of users (helpdesk operators). these operators will assign the incidents based on the category & impact and so on….

    I am not able to figure out how to assign all the new incidents automatically to helpdesk, i have a DL created in AD for helpdesk.

  5. @ Bjkoekkoek

    We are getting the same error abour date formatting. However I cannot understand your solution? Did you change the date format?

  6. @Vitaliy

    We are encountering the same problem. I managed to figure out that it has something to do with the format of the date parameter. When I use 07-08-2011(7th of august) everything works fine but when I use 13-08-2011(13th of august) it all goes wrong…

  7. i use this blod http://contoso.se/blog/?p=1875 but i get an error in powershell script

    Get-SCSMIncident : CreatedDate_6258638D_B885_AB3C_E316_D00782B8F688=’15.04.2011 14:01:51′ — String was not recognized
    as a valid DateTime.
    At C:\Users\scsm\Desktop\UnAssigned.ps1:21 char:31
    + $getIncidents=Get-SCSMIncident <<<< -Status "Active" -CreatedBefore $BeforeDate | where { $_.AssignedTo -eq $NULL }
    | select ID, Title, AffectedUser
    + CategoryInfo : NotSpecified: (:) [Get-SCSMIncident], UnknownDatabaseException
    + FullyQualifiedErrorId : Microsoft.EnterpriseManagement.Common.UnknownDatabaseException,SMLets.SCSMIncidentGet

    as i understood error is in this string -CreatedBefore $BeforeDate but why??

Leave a Reply

Your email address will not be published. Required fields are marked *