#  Script:   Copy Parent Description to Child Activities (Append)
#  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)"
    If ($Activity.Description -eq $null)
        $Activity | Set-SCSMObject -Property Description -Value $Parent.Description
        $AppendedDescription = $Activity.Description + "`n" + $Parent.Description
           $Activity | Set-SCSMObject -Property Description -Value $AppendedDescription 
Write-Host "Script Complete"