Need help coding powershell in relation to SCSM

Konstantin 41 Reputation points
2021-12-24T04:31:24.127+00:00

Good day! Please tell me how to use powershell to read information from the Log Entry at the Incident in SCSM (analyst comments, time / date)?

Service Manager
Service Manager
A family of System Center products for managing incidents and problems.
210 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,382 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 97,396 Reputation points MVP
    2021-12-24T20:25:21.9+00:00

    Hi @Konstantin ,

    please take a look here if it helps with your requirement:
    https://github.com/abaumgarten42/SCSM_Useful_PSscripts/blob/main/Get-IncidentComments.ps1

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. DaveK 1,846 Reputation points
    2021-12-24T08:57:02.72+00:00

    Hi, You don't mention your level of Powershell experience or if you've tried anything already but you could take a look into SMlets. Its a set of PowerShell cmdlets for SCSM which might have some options for reading back. I've used them to log calls, attached files etc so might have what you need. Couple year old now so I'm not sure if there are any newer options available or native PowerShell modules.

    https://www.powershellgallery.com/packages/SMLets/1.0.2016.0

    0 comments No comments

  2. Andreas Baumgarten 97,396 Reputation points MVP
    2022-08-05T12:04:15.943+00:00

    Hi @Konstantin ,

    first: As your first question is marked as answer it's better to open a new question. I just found your additional question by "accident" ;-)

    Here we go:

    There are 4 tables involved:
    MT_System$WorkItem$Incident -> Contains the Incident details
    RelationshipType -> contains the Relationship Types (we need the System.WorkItem.TroubleTicketHasAnalystComment relationship )
    Relationship -> contains the individual Incident ID (SourceID) and the individual Analyst Comment ID (TargetID)
    System.WorkItem.TroubleTicketHasAnalystComment -> contains the individual Analyst Comment

    Single queries:

    /* Get Incident by ID  
    */  
    SELECT Id_9A505725_E2F2_447F_271B_9B9F4F0D190C,BaseManagedEntityId FROM MT_System$WorkItem$Incident  
      WHERE Id_9A505725_E2F2_447F_271B_9B9F4F0D190C like 'IR2223'  
      
    /* Get RelationshipType by name  
    */  
    SELECT RelationshipTypeId, RelationshipTypeName FROM RelationshipType  
    WHERE RelationshipTypeName like 'System.WorkItem.TroubleTicketHasAnalystComment'  
      
    /* Get Related comments  by SourceEntityId (BaseManagedEntityId if Incident) and Relationship "System.WorkItem.TroubleTicketHasAnalystComment  
    */  
    SELECT SourceEntityId, TargetEntityId FROM Relationship  
    WHERE RelationshipTypeId like '835A64CD-7D41-10EB-E5E4-365EA2EFC2EA' AND  
    SourceEntityId like '012FA8A9-E3C3-B0EF-3B56-879FA13A9B81'  
      
    SELECT * FROM MT_System$WorkItem$TroubleTicket$AnalystCommentLog  
    WHERE BaseManagedEntityId like '3E3E0615-4E43-6B34-A6D7-60D5693DB819'  
    

    One query:

    SELECT Comment_AECE7B96_331B_498C_2F77_AEA4376EFFF1 FROM MT_System$WorkItem$TroubleTicket$AnalystCommentLog  
    WHERE BaseManagedEntityId in (SELECT TargetEntityId FROM Relationship  
    WHERE RelationshipTypeId in (SELECT RelationshipTypeId FROM RelationshipType  
    WHERE RelationshipTypeName like 'System.WorkItem.TroubleTicketHasAnalystComment') AND  
    SourceEntityId in (SELECT BaseManagedEntityId  FROM MT_System$WorkItem$Incident  
    WHERE Id_9A505725_E2F2_447F_271B_9B9F4F0D190C like 'IR2223'))  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments