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.
- Open Service Manager Authoring Tool and create a new management pack, in my case Contoso.Unassigned
- Right-click Workflows and create a new workflow
- In the Create Workflow Wizard, General, input a name, for example ContosoUnassignedIncidents
- In the Create Workflow Wizard, Trigger Condition, select Run at a scheduled time or at…
- In the Create Workflow Wizard, Trigger Criteria, select Other interval and 1 Hours
- In the Workflow window, from the toolbox, drag and drop the Windows PowerShell Script
- 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, AffectedUserif ($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
- Modify the following parameters to fit your environment
- Save your management pack
- Copy the ContosoUnassignedIncidents.dll to the C:\Program Files\Microsoft System Center\Service Manager 2010 directory on your Management Server
- 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.
i want the script of following criteria
notify on unassigned incident of Tier 2 support group.
Hi, if you follow the blogpost you will build it yourself. Dont have it around, sorry. Today you could also build this in Orchestrator or Opalis.
Could any of you guys enlighten me on how to get a hand on this ContosoUnassignedIncidents.dll ?
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.
Dear
i want to run this workflow only in working hours
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?
I will appropriate away grab your rss feed to remain up to date on any succeeding articles you might write
Hi, thanks for reading my blog. You could try run the script manually and see what you get as output.
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.
@ Bjkoekkoek
We are getting the same error abour date formatting. However I cannot understand your solution? Did you change the date format?
My workflow is working. However I dont receive any email??
Hello
I can not run for Microsoft sendemail servitse manager 2010. Where can I find the logs?
@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…
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??
Nice one!
[…] This post was mentioned on Twitter by FAQShop, FAQShop. FAQShop said: [http://www.contoso.se] Notification on all unassigned incidents: I saw a question in the forum today about notification … http://bit.ly/c8evlp […]