Need help on powershell coding regarding SCSM

jansi rani krishnan 601 Reputation points
2021-08-02T10:27:33.26+00:00

Hi Team,

I am working on updating incident form in SCSM through a PowerShell script.

I have the value of a variable "$ResponseObject.Result" like below
119345-image.png

I would like to store the sys_id and SNOW ticket number in one of the field in the Incident form in SCSM. But the below code is not working. Any help is highly appreciated.
if ($Responseobject.result.status -eq "inserted")
{
$UpdateAlternateContact=@"
sys_id=$Responseobject.result.sys_id
SNOW Ticket Id=$Responseobject.result.number

"@
}

Set-SCSMObject -SMObject $IO -Property "AlternateContactMethod" -value $UpdateAlternateContact

Any help is highly appreciated.

Regards,
Jansi

Service Manager
Service Manager
A family of System Center products for managing incidents and problems.
237 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,551 questions
{count} votes

Accepted answer
  1. Andreas Baumgarten 111.3K Reputation points MVP
    2021-08-02T14:17:42.253+00:00

    Hi @jansi rani krishnan ,

    here we go:

    Import-Module SMlets  
    $smdefaultserver = "SCSM1"  
    # Define properties  
    $irID = "IR2103"  
    $SysID = "c21f57971b6d7c101d777b75464bcb26"  
    $SNOWticketID = "INC0055836"  
    $status = "inserted"  
    ######  
    $irClass = Get-SCSMclass -name System.Workitem.Incident$  
    # Get SCSM objects  
    $irObj = Get-SCSMObject -Class $irClass -Filter "ID -eq $irID"  
    # Update IR Alternate Contact Method  
    if (($status -eq "inserted") -and ($irObj)) {  
        $UpdateAlternateContact = "Sysid: $SysID | SNOW ticket number: $SNOWticketID | Correlation_id: $irID"  
        Set-SCSMObject -SMObject $irObj -Property "ContactMethod" -value $UpdateAlternateContact  
    }  
    

    ----------

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

    Regards
    Andreas Baumgarten


2 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 111.3K Reputation points MVP
    2021-08-03T09:04:18.003+00:00

    Hi @jansi rani krishnan ,

    the "Alternate Contact Method" text field in the Incident form is a single line. Using values 3 different lines might be not optimal.

    But anyway. If you like the values in 3 lines please try this:

     Import-Module SMlets  
     $smdefaultserver = "SCSM1"  
     # Define properties  
     $irID = "IR2103"  
     $SysID = "c21f57971b6d7c101d777b75464bcb26"  
     $SNOWticketID = "INC0055836"  
     $status = "inserted"  
     ######  
     $irClass = Get-SCSMclass -name System.Workitem.Incident$  
     # Get SCSM objects  
     $irObj = Get-SCSMObject -Class $irClass -Filter "ID -eq $irID"  
     # Update IR Alternate Contact Method  
     if (($status -eq "inserted") -and ($irObj)) {  
         $UpdateAlternateContact = "Sysid: $SysID `r`n SNOW ticket number: $SNOWticketID `r`n Correlation_id: $irID"  
         Set-SCSMObject -SMObject $irObj -Property "ContactMethod" -value $UpdateAlternateContact  
     }  
    

    ----------

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

    Regards
    Andreas Baumgarten


  2. Andreas Baumgarten 111.3K Reputation points MVP
    2021-08-03T10:18:01.48+00:00

    Hi @jansi rani krishnan ,

    here we go:

    # Alternate Contact Method property  
    $a = "SNOW SYS ID: c21f57971b6d7c101d777b75464bcb26 | SNOW INCIDENT NUMBER: INC0055836 | SNOW CORRELATION ID: IR6177"  
    # Get SysID  
    $sysID = ($a.Split("|")[0].Split(":").Trim())[1]  
    $SysID  
    # Get SNOW Ticket ID  
    $SNOWticketID = ($a.Split("|")[1].Split(":").Trim())[1]  
    $SNOWticketID  
    # Get SCSM IR ID  
    $irID = ($a.Split("|")[2].Split(":").Trim())[1]  
    $irID  
    

    ----------

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

    Regards
    Andreas Baumgarten


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.