Update the Manual Activity in SCSM via PowerShell

jansi rani krishnan 601 Reputation points
2021-07-27T18:06:16.72+00:00

Hi Team,

I need some help in updating Manual Activity (associated to an incident) via PowerShell. Below are the fields in Manual Activity that I would like to update for a MA.

Title
Description
Activity Implementer
Priority
Status
SupportGroup
Scheduled Start Date
Scheduled End Date
Notes/Comments

Appreciate your help!!!

Regards,
Jansi

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

Accepted answer
  1. Andreas Baumgarten 104K Reputation points MVP
    2021-07-27T19:56:57.897+00:00

    Hi @jansi rani krishnan ,

    a SCSM Manual Activity doesn't have the property SupportGroup.
    I wasn't sure if all properties of the Manual Activity will be updated or only some. The following script will test each property if it will be updated. If you don't want to update a property don't enter a value for the property. For instance $maTitle = ""

    Please try this:

    Import-Module SMlets  
    $smdefaultserver = "SCSM1"  
    # Define Manual Activity properties  
    $irID = "IR2103"  
    $maTitle = "Update Test MA by PowerShell32"  
    $maDescription = "Update Test Description 32"  
    $maPriority = "Medium"  
    $maArea = "Other"  
    $maStatus = "In Progress"  
    $maAssignedToUser = "ppan1234"  
    $maNotes = "Update Note 32"  
    $maScheduledStartDate = "07/29/2021 13:00" # UTC time  
    $maScheduledEndDate = " 07/30/2021 11:00"  # UTC time  
    ######  
    $relAssignedToUser = Get-SCSMRelationshipClass -Name System.WorkItemAssignedToUser  
    $relWIcontainsActivity = Get-SCSMRelationshipClass -Name System.WorkItemContainsActivity  
    $irClass = Get-SCSMclass -name System.Workitem.Incident$  
    $maClass = Get-SCSMclass -name System.Workitem.Activity.ManualActivity$  
    $UserClass = Get-SCSMClass -name System.Domain.User$  
    # Get SCSM objects  
    $irObj = Get-SCSMObject -Class $irClass -Filter "ID -eq $irID"  
    $maObj = Get-SCSMRelatedObject -SMObject $irObj -Relationship $relWIcontainsActivity  
    $maAssignedToUserObj = Get-SCSMObject -Class $UserClass -Filter "UserName -eq $maAssignedToUser"  
    # Update properties  
    if ($maTitle -and $maObj) {  
        $maObj | Set-SCSMObject -Property Title -Value $maTitle  
    }  
    if ($maDescription -and $maObj) {  
        $maObj | Set-SCSMObject -Property Description -Value $maDescription  
    }  
    if ($maPriority -and $maObj) {  
        $maObj | Set-SCSMObject -Property Priority -Value $maPriority  
    }  
    if ($maArea -and $maObj) {  
        $maObj | Set-SCSMObject -Property Area -Value $maArea  
    }  
    if ($maStatus -and $maObj) {  
        $maObj | Set-SCSMObject -Property Status -Value $maStatus  
    }  
    if ($maNotes -and $maObj) {  
        $maObj | Set-SCSMObject -Property Notes -Value $maNotes  
    }  
    if ($maScheduledStartDate -and $maObj) {  
        $maObj | Set-SCSMObject -Property ScheduledStartDate -Value $maScheduledStartDate  
    }  
    if ($maScheduledEndDate -and $maObj) {  
        $maObj | Set-SCSMObject -Property ScheduledEndDate -Value $maScheduledEndDate  
    }  
    if ($maAssignedToUserObj -and $maObj) {  
        New-SCSMRelationshipObject -RelationShip $relAssignedToUser -Source $maObj -Target $maAssignedToUserObj -Bulk  
    }  
    

    Script on GitHub: https://github.com/abaumgarten42/SCSM_Useful_PSscripts/blob/main/Update-MArelatedToIR.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.

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 104K Reputation points MVP
    2021-07-28T13:40:58.13+00:00

    Hi @jansi rani krishnan ,

    if you have more than one Manual Activity in an Incident you need to filter the Manual Activities by ID or Title.

    Add one of the options below between line 22 and 23 of the script I posted.

    # Filter by Title  
    $maObj = $maObj | Where {$_.Title -eq 'Update Test MA by PowerShell32'}  
      
    # Filter by ID  
    $maObj = $maObj | Where {$_.ID -eq 'MA2114'}  
    

    ----------

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

    Regards
    Andreas Baumgarten