I had this nightmare to update comments in workflow task, first I thought it’s easy but it turned out we cannot just update the extended properties of workflow (it’s easy using code but not with script) and you are aware I like PowerShell and was trying to change the value (string) that was in comments field (which is a property in workflow extended properties)

And here is script guys , NJOY ..

Note: I actually did not modify the extended property i tricked it using the PowerShell Powerness of replacing the string :D.

$w = Get-SPWeb "http://SharePoint/Sites/Test" #Change this
$list = $w.Lists["NewList"] #Change this
$i = $list.GetItemByID(10) # Change this
$workflows = $i.workflows
try
{
Foreach ($workflow in $workflows)
{
$tasks = $workflow.Tasks
Foreach ($task in $tasks)
{
if($task["Title"] -eq "Review required on item 1034")
{
	$task["Outcome"] = "Approved"
	$prop = $task["ExtendedProperties"] #Bingo
	$oldComment = "Testing the Reject and will also test comments." #the comment that you want  to change
	$newComment = "This is changing using PS Script" 
	$prop = $prop -replace $oldComment,$newComment
	$task["ExtendedProperties"] = $prop
	Write-Host $prop

}
$task.Systemupdate()
}
} 
}
Catch
{
 Write-Host -ForegroundColor Red $_.Exception.ToString()
}
write-host -ForegroundColor Green "done."

By Indra

SharePoint Architect

Leave a Reply