Mehrfach tauchte die Anforderung auf, eine Mail mit einer Liste aller Incidents zu verschicken, die nicht zugewiesen sind. Mit Hilfe eines PowerShell Skripts lässt sich dies umsetzen.
Hier die im Skript verwendeten/berücksichtigen Kriterien:
- Incidents, die vor mehr als 30 Minuten erstellt wurden und nicht zugwiesen sind.
- Dabei sollen die Incidents nur der Support Gruppe “Tier 1″ angehören.
- Ebenfalls sollen nur Incidents mit dem Status “Active” berücksichtigt werden.
Für die Umsetzung werden die SMLets benötigt: http://smlets.codeplex.com
Hier das PowerShell Skript:
—
# Import SMlets modul
Import-Module SMlets
# Configure your mail server, the recipient and the sender of the mail
$smtphost=”mailserver.yourdomain.local”
$to=”administrator@yourdomain.local”
$from=”mail@yourdomain.local”
# Configure time value “Incident is created before xy minutes”
$CreatedBefore = 30
# Configure the Support Group / Tier Queue
$SupportGroup = “Tier1″
# 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
$BeforeDate = (get-date).AddMinutes(-$CreatedBefore).ToString(“MM/dd/yyy HH:mm:ss”)
$Active = Get-SCSMEnumeration IncidentStatusEnum.Active$
$TierQueue = (Get-SCSMEnumeration IncidentTierQueuesEnum.$SupportGroup$)
#$TierDisplayname = $TierQueue.Displayname
$AssignedUserObjectRelClass = Get-SCSMRelationshipClass System.WorkItemAssignedToUser
$IncidentClass = Get-SCSMClass -Name System.WorkItem.Incident$
$Output = ‘ID – Title <br>’
$Counter = 0
#Get all acitiv incidents from tier queue created xy minutes before
$Incidents = Get-SCSMObject -Class $IncidentClass | where {($_.Status -eq $Active -AND $_.TierQueue -eq $TierQueue -AND ($_.CreatedDate) -lt $BeforeDate)}
#Get all unassigned incidents from list
foreach ($Incident in $Incidents)
{
$AssignedUser = Get-SCSMRelatedObject -SMObject $Incident -Relationship $AssignedUserObjectRelClass
If ($AssignedUser.Displayname -eq $NULL)
{
$AssignedUser
$Counter = $Counter + 1
$Output = $Output + “`r`n`r`n” + $Incident.ID + ‘ – ‘ + $Incident.Title + ‘ <br>’
}
}
$Output
# If there is any unassigned incident send a mail with a list of these incidents
if ($Counter -gt 0)
{ $subject = “Unassigned incidents in Service Manager Support Group “+ $TierQueue.Displayname + “, total of ” + $Counter
$body = $Output
Send-Mail $from $to $subject $body
}
Remove-Module SMlets
—
Hier das Ergebnis:
Und hier das Skript als Download: MailNotificationUnassignedIncidents-V0.2.ps1 (bitte die Dateiendung von txt auf ps1 ändern)
Getestet mit SCSM 2012 RC und SCSM 2010 SP1 CU3.
Tags: Notification, Powershell, SCSM
