#----------------------------------------------------------------------------------------------------------
#  Script:   Copy Parent Description to Child Activities (overwrite)
#  Author:   www.xapity.com
#  Date:     06-10-2016
#  Version:  1.0
#  Comments: Used in a Xapity PowerShell Activity to copy the description field from the Parent work item
#            to all child Activities. It will overwrite the child Activity description field.
#---------------------------------------------------------------------------------------------------------
Import-Module SMLets -Force
If ($ParentID -like "CR*")
    {$Class = Get-SCSMClass -name System.WorkItem.ChangeRequest$}
ElseIf ($ParentID -like "SR*")
    {$Class = Get-SCSMClass -name System.WorkItem.ServiceRequest$}
Else {Write-Host "Bad Class - Script will fail"}

Write-Host "Class is : $Class"

$Parent = Get-SCSMObject -Class $Class -Filter "ID -eq $ParentID"

Write-Host "The Parent ID is $ParentID"

$Activities = Get-SCSMRelatedObject -SMObject $Parent -Depth Recursive | ?{$_.TypeName -like "System.WorkItem.Activity.*"}
foreach ($Activity in $Activities)
{
    Write-Host "Activity Updated $($Activity.id) with Title $($Activity.Title)"
    $Activity | Set-SCSMObject -Property Description -Value $Parent.Description
}
Write-Host "Script Complete"