Retrieve End-User and Analyst comments for an incident

Jun 12, 2012 at 7:41 AM

Hi all,

 

is there a way to query the End-User and Analyst comments created in a particular incident by using the PowerShell SMlets?

I've noticed there's a way to create new Analyst comments by using the "set-scsmincident -comment" cmdlet but I couldn't find a way to retrieve them back. Apparently the comment switch does not exist for the get-scsmincident cmdlet?!

 

Any help is very appreciated!

Thanks

Alex 

Jun 13, 2012 at 7:36 AM
Edited Jun 15, 2012 at 10:24 AM

Have sorted this now. If anyone is interested below is the code I wrote to get the comments and extract them with some additional data into a CSV like file.

You need to change the classes and filter criteria of course if you want to re-use this script. AppliesTotroubleTicket is basically the attribute which stores the action log + comments so that's what you need to query via PowerShell.

 

Import-Module SMlets -CMDlet get-scsmclass,get-scsmobject,get-scsmincident

$AllComments = ""
$IncidentDefInfos = ""
$Incident = ""
$Comment = ""
$IncidentsID = ""
$AllCommentsResults = ""

$incidentextension = get-scsmclass -name ClassExtension_4b8fb113_d448_4757_8a3c_28b7e37e5111;
$IncidentsID = get-scsmobject -class $incidentextension | where {$_.BusinessApplication -ne $NULL -AND $_.Status -notlike "*Resolved*"} | select ID

foreach ($Incident in $IncidentsID)
{
    $IncidentDefInfos = get-scsmincident -ID $Incident.ID
    $FilteredIncidents = $IncidentDefInfos.AppliesToTroubleTicket | where {$_.ClassName -eq "System.WorkItem.TroubleTicket.UserCommentLog" -OR $_.ClassName -eq "System.WorkItem.TroubleTicket.AnalystCommentLog"}   
    if ($FilteredIncidents.count -gt 0)
    {
        foreach ($Comment in $FilteredIncidents)
        {
            $UserComment = ""
            $AnalystComment = ""
            $ClassName = ""
            $ClassName = $Comment | select ClassName
            Switch($ClassName.ClassName)
            {
                "System.WorkItem.TroubleTicket.UserCommentLog" {$UserComment = $Comment | select EnteredDate, EnteredBy, Comment}
                "System.WorkItem.TroubleTicket.AnalystCommentLog" {$AnalystComment = $Comment | select EnteredDate, EnteredBy, Comment, IsPrivate}
            }
         $IncidentComments = $Incident.ID + '","' + $UserComment.EnteredDate + '","' + $UserComment.EnteredBy + '","' + $UserComment.Comment + '","' + $AnalystComment.EnteredDate + '","' + $AnalystComment.EnteredBy + '","' + $AnalystComment.Comment + '",' + $AnalystComment.IsPrivate + "`r`n"
         $AllIncidentComments += $IncidentComments
        }
    }
}

write-host $AllIncidentComments
Out-File  -InputObject $AllIncidentComments -FilePath C:\Software\AllComments.csv

Remove-Module SMlets

PS: Can someone point me out how to use the -Filter switch correctly if you need to filter on two attributes, please? I'd like to get rid of the 'where' filtering to optimize the script performance.


Cheers

Alex