I have written the below code but, the output is repeated for arount 37 times. Can anyone please help me to find where I am wrong.

$site = Get-SPSite -Identity $Url
        $root = $site.RootWeb
        $bu1web = $site.OpenWeb("Bu1")
        $requestitems = $listRequest.items

        if($listRequest -ne $null ) 
            foreach($requestitem in $requestitems)
                foreach($workflow in $requestitem.workflows)

                    foreach($history in $historys)
                        if(($history["Description"] -eq "No User/Group assigned to the task.") -And (($workflow.InternalState -eq "Running, Faulting") -Or ($workflow.InternalState -eq "Cancelled, Faulting")))
                                #Write-Log $("Request ID:"+$requestitem["ID"] + "--WorkFlowName:" +$workflow.ParentAssociation.Name) $logFile "info"    
                                Write-Log $("Request ID:"+$requestitem["ID"]+"--Status:"+$workflow.InternalState+"--Event Type:"+$history["EventType"] + "--Description:" +$history["Description"]) $logFile "info"           
                    }#end of foreach workflow loop
            }# end of checking if workflow associations count is greater than one
        }#end ofRequest list null check

Thanks in Advance

1 Answer 1


$workflow.HistoryList.Items get all the history of the workflow history list in the site, not only for an item.

You need to filter with workflow instance ID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.