{"id":1875,"date":"2010-09-23T15:14:38","date_gmt":"2010-09-23T13:14:38","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=1875"},"modified":"2010-09-23T15:14:38","modified_gmt":"2010-09-23T13:14:38","slug":"notification-on-all-unassigned-incidents","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=1875","title":{"rendered":"Notification on all unassigned incidents"},"content":{"rendered":"<p>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.<\/p>\n<ol>\n<li>Open Service Manager Authoring Tool and create a new management pack, in my case Contoso.Unassigned<\/li>\n<li>Right-click Workflows and create a new workflow<\/li>\n<li>In the Create Workflow Wizard, General, input a name, for example ContosoUnassignedIncidents<\/li>\n<li>In the Create Workflow Wizard, Trigger Condition, select Run at a scheduled time or at&#8230;<\/li>\n<li>In the Create Workflow Wizard, Trigger Criteria, select Other interval and 1 Hours<\/li>\n<li>In the Workflow window, from the toolbox, drag and drop the Windows PowerShell Script<a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned01.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-1876\" title=\"Unassigned01\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned01-300x246.jpg\" alt=\"\" width=\"300\" height=\"246\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned01-300x246.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned01.jpg 484w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<li>In the properties of the script activity, paste the following script into the script body field<br \/>\n<blockquote><p>$smtphost=&#8221;LUDSRV206&#8243;<br \/>\n$to=&#8221;kurt@contoso.local&#8221;<br \/>\n$from=&#8221;svc-wf-ludsrv204@contoso.local&#8221;<\/p>\n<p>function Send-Mail<br \/>\n{<br \/>\nparam($From,$To,$Subject,$Body)<br \/>\n$smtp = new-object system.net.mail.smtpClient($smtphost)<br \/>\n$mail = new-object System.Net.Mail.MailMessage<br \/>\n$mail.from= $From<br \/>\n$mail.to.add($To)<br \/>\n$mail.subject= $Subject<br \/>\n$mail.body= $Body<br \/>\n$mail.isbodyhtml=$true<br \/>\n$smtp.send($mail)<br \/>\n}<\/p>\n<p>Import-Module SMLets<br \/>\n$BeforeDate = (get-date).AddHours(-2).ToString(&#8220;yyy-MM-dd HH:mm:ss&#8221;)<br \/>\n$getIncidents = Get-SCSMIncident -Status &#8220;Active&#8221; -CreatedBefore $BeforeDate | where { $_.AssignedTo -eq $NULL } | select ID, Title, AffectedUser<\/p>\n<p>if ($getIncidents.count -gt 0) {<\/p>\n<p>$subject= &#8220;Unassigned incidents in Service Manager, total of &#8221; + $getIncidents.count<br \/>\n$body=$getIncidents|convertto-html<br \/>\nSend-Mail $from $to $subject $body<\/p>\n<p>}<\/p>\n<p>Remove-Module SMLets<\/p><\/blockquote>\n<\/li>\n<li>Modify the following parameters to fit your environment\n<ul>\n<li>$smtphost = hostname of your mailserver<\/li>\n<li>$to = the e-mail address that will recive the e-mail<\/li>\n<li>$from = the e-mail address that the script will use to send the e-mail<\/li>\n<li>$subject = the subject in the e-mail<a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned02.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-1880\" title=\"Unassigned02\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned02-300x202.jpg\" alt=\"\" width=\"300\" height=\"202\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned02-300x202.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned02-1024x691.jpg 1024w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned02.jpg 1037w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>Save your management pack<\/li>\n<li>Copy the ContosoUnassignedIncidents.dll to the C:\\Program Files\\Microsoft System  Center\\Service Manager 2010 directory on your Management Server<\/li>\n<li>Import your management pack into Service Manager<\/li>\n<\/ol>\n<p>After a hour the e-mail address in your $TO parameter (in the script) could get a e-mail looking like this<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned03.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-1882\" title=\"Unassigned03\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned03-300x198.jpg\" alt=\"\" width=\"300\" height=\"198\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned03-300x198.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned03-1024x676.jpg 1024w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned03.jpg 1281w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>In this e-mail we can see all incidents older then two hours that don&#8217;t have anyone in &#8220;assigned to&#8221;. 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 \ud83d\ude42 Also, please not that my scrip needs the Service Manager cmdlets, more info about them <a href=\"http:\/\/blogs.litware.se\/?p=711\">here<\/a>.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned04.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-1885\" title=\"Unassigned04\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned04-300x173.jpg\" alt=\"\" width=\"300\" height=\"173\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned04-300x173.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned04-1024x591.jpg 1024w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2010\/09\/Unassigned04.jpg 1186w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=1875\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[25],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1875"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1875"}],"version-history":[{"count":11,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1875\/revisions"}],"predecessor-version":[{"id":2657,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1875\/revisions\/2657"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1875"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}