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")
$listRequest=$bu1web.Lists["Requests"]
$requestitems = $listRequest.items
if($listRequest -ne $null )
{
foreach($requestitem in $requestitems)
{
foreach($workflow in $requestitem.workflows)
{
$historys=$workflow.HistoryList.Items
#$tasks=$workflow.Tasks
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