locked
Script Notification Help RRS feed

  • Question

  • I am trying to modify one of Andreas Baumgarten's script.  Rather than the assigned user getting a notification, I want the manager to get a list of incidents - similar to his Unassigned script.  I just want to add the Assigned to users name in the message of each incident.  Currently the script runs and I am sent a list of incidents that have not been modified in X number of days, but I get the same users name for all the incidents, so its rather inaccurate.  All I've really done to the script is add $AssignedUser.DisplayName in the $Output.  Here it is:

    # Import SMlets module  
    Import-Module SMlets -force 
      
    $smtphost = "..."
    $to = "..." 
    $from = "..." 
     
    # Send-Mail function  
    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)  
        } 
         
    # Some other variables     
    $LastModifiedBreached = New-Object Timespan 5,0,0,0,0
    $incidents = Get-SCSMIncident -Status active |?{$_.LastModified -lt (Get-Date).Subtract($LastModifiedBreached)}
    $incident
    $AssignedUserObjectRelClass = Get-SCSMRelationshipClass System.WorkItemAssignedToUser
    
    
    $Incidents.count 
    
    foreach ($Incident in $Incidents) 
    {
    	$AssignedUser = Get-SCSMRelatedObject -SMObject $incident -Relationship $AssignedUserObjectRelClass 
    
            If ($AssignedUser.Displayname -ne $NULL)         
            { 
     	    $AssignedUser
            $Counter = $Counter + 1 
            $Output = $Output + "`r`n`r`n" + $Incident.ID + ' : ' + $AssignedUser.Displayname + ' : ' + $Incident.Title + ' | ' + $Incident.LastModified + ' <br>' 
    	    }
       }
    $Output 
      
    # If there is any unassigned incident send a mail with a list of these incidents  
     
         $subject = “Incidents that have not been modified in 3 days ”
          $body = $Output 
     Send-Mail $from $to $subject $body  
        
      
    Remove-Module SMlets -force


    - Get on the floor, do that dinosaur



    • Edited by Pete Barbuto Tuesday, October 1, 2013 2:44 PM typos
    Tuesday, October 1, 2013 2:42 PM

Answers

  • I got it working.

    - Get on the floor, do that dinosaur

    • Marked as answer by Pete Barbuto Tuesday, October 1, 2013 7:15 PM
    Tuesday, October 1, 2013 7:14 PM

All replies

  • This might help; heres the error that I receive before the list of incidents is populated:

    Get-SCSMRelatedObject : Cannot bind parameter 'SMObject'. Cannot convert the "@{__base=Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectProjection; Object=IR6662

    Also, this is a 2012 sp1 fully updated environment. 


    - Get on the floor, do that dinosaur

    Tuesday, October 1, 2013 3:04 PM
  • I got it working.

    - Get on the floor, do that dinosaur

    • Marked as answer by Pete Barbuto Tuesday, October 1, 2013 7:15 PM
    Tuesday, October 1, 2013 7:14 PM