I've asked this question previously and am always pointed to code similar to below. Unfortunately though I can see workflows listed as running in the UI for the List, this never finds any of them.
Can someone see anything wrong with this code? Or is it not relevant for 2013 workflows?
When I have and errant workflow and DO NOT KNOW the document, I can't cancel it via the UI. If it is looping and/or eating up CPU this is a big issue for me.
Thanks.
$spSite = Get-SPSite "http://myserver/mysite/mycollection" # SiteCollection
$spWeb = $spSite.OpenWeb() # Evt. (sub)Web kan hier
for($i = 0; $i -le $spWeb.Lists.Count;$i++)
{
write-host "List:" $spWeb.Lists[$i].title
foreach($folder in $list.Folders)
{
$query = New-Object -Type 'Microsoft.SharePoint.SPQuery'
$query.Folder = $folder.Folder
$folderItems = $list.GetItems($query)
foreach($item in $folderItems)
{
#write-host $item.Title
foreach ($workflow in $item.Workflows)
{
write-host "Found A Workflow" <--- NOTHING IS EVER RETURNED
}
}
}
}
Tom