question

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

Update the Manual Activity in SCSM via PowerShell

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

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
1 Vote"
AndreasBaumgarten answered jansiranikrishnan-1796 commented

Hi @jansiranikrishnan-1796 ,

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
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,

Thank you so much. It is working if the incident has got only one MA associated with it. Suppose if the incident has got more than one MA associated with it, Then how to do the update only for the particular MA.

Any pointer is greatly appreciated.

Regards,
Jansi

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

Hi @jansiranikrishnan-1796 ,

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

· 2
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.

Thank you so much Andreas for sharing information. It is working to update any particular MA.

Regards,
Jansi

0 Votes 0 ·

Hi Andreas,

Do you have any private blog or Q&A forum where i would like to ask an advice regarding career guidance?

It would be great if you can share the email-id/link of any such platform.

Regards,
Jansi

0 Votes 0 ·