question

jansiranikrishnan-1796 avatar image
0 Votes"
jansiranikrishnan-1796 asked jansiranikrishnan-1796 commented

Need powershell help to retrieve incident information

Hi Team,

I have a requirement to retrieve a particular incident information

Example:

I can fetch the whole set of incident information using the below command.

$IC=get-SCSMclass -name system.workitem.incident$
$IO=get-SCSMobject -class $IC | select-object *

I have no idea on how to retrieve a particular data like Title, Description, urgency, impact individually and store in a separate variable

Can anyone please help me out on how to proceed?

It would really be a great help!!!

Thanking you in advance.

Regards,
-Jansi

windows-server-powershellmsc-service-manager
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered jansiranikrishnan-1796 commented

Hi. @jansiranikrishnan-1796 ,

maybe this will help:

 Import-module SMlets # Implort SMLets module
 $smdefaultserver = "SCSM1" # Define SCSM Management Server
 $IRid = "IR2031" # Define Incident Record
 $IRclass=Get-SCSMclass -name System.Workitem.Incident$ # Get SCSM Incident class object
 $IRobject=Get-SCSMobject -class $IRclass -filter "ID -eq $IRid" # Get IR object
 $IRobject | fl # show all properties and values of the IR object
    
 # Set dedicated variables with IR properties
 $Title = $IRobject.Title
 $Description = $IRobject.Description
 $Status = $IRobject.Status
 $Impact = $IRobject.Impact
 $Urgency = $IRobject.Urgency
 $Id = $IRobject.Id
 $CreatedDate = $IRobject.CreatedDate
 $LastModifiedDate = $IRobject.LastModified
 $Classification = $IRobject.Classification.DisplayName
 $SupportGroup = $IRobject.TierQueue.DisplayName

If you like you can take a look here for some more SCSM related PowerShell scripts. These scripts were published in the Microsoft TechNet Gallery before (which is retired now):
https://github.com/abaumgarten42/SCSM_Useful_PSscripts


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

Regards
Andreas Baumgarten




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Andreas,

This is an extraordinary answer. Thank you so much.

This is not working "$IRobject | fl" from the above response. Is this correct?

Also I need help on the Description field, in my case it is returning almost 10-12 lines of text (example as below)

Line1: Request Type: General Incident
Line2: Description: This incident is created for testing purpose
Line 3: Urgency: Low
Line 4: User Affected: Single User

Here, How to retrieve Description value from Line 2 "This incident is created for testing purpose"

Awaiting for your response eagerly,

Thanking you,
Jansi

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered jansiranikrishnan-1796 commented

Hi @jansiranikrishnan-1796 ,

the line $IRobject | fl should just output the full Incident Record with all fields and values. Works here ... but is not important for the rest of the script.

To get the second line of Description you can give this a try:

 $Description = "This is line 1
 This is line 2
 This is line 3"
 $secondLine = ($Description.Split([Environment]::NewLine))[1] # Number starts with 0 for first line
 $secondLine


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

Regards
Andreas Baumgarten


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi Andreas,

You are superb man. Excellent.

$secondLine = ($Description.Split([Environment]::NewLine))[1] --> this is working

I got the secondline as "Description : This incident is created for testing purpose"

How should we get only "This incident is created for testing purpose" from the second line.

Any inputs is greatly appreciated!

Thanking you,
Jansi

0 Votes 0 ·

Here we go:

 $secondLine = (($Description.Split([Environment]::NewLine))[1]).Replace("Description : ","")


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

Regards
Andreas Baumgarten



0 Votes 0 ·

Awesome Andreas :) This is working. Thank you so much for your inputs. This really helps me a lot.

Regards,
Jansi

0 Votes 0 ·