Asked by:
Generate workflow report for all Running and Canceled state workflows in SharePoint 2010

Question
-
Hi All
Below script generates the output for all in-progress and completed workflows in SharePoint 2010,hence it is working for Subsite level.
Could any one please help me to run at SC level ,so that where it can cover all underneath subsites in one report.
$output="c:\Workflows.csv" #Write Header to CSV File "Site `t List `t ListItem `t Workflow Status `t Workflow Name " | out-file $output $webURL = "http://sharepoint/ps" $web=get-spweb $weburl $lists = $web.lists foreach($list in $lists){ foreach($item in $list.items) { foreach($workflow in $item.workflows) { $result ="$($web.url) `t $($list.Title) `t $($workflow.ItemName)`t $($workflow.InternalState) `t $($workflow.ParentAssociation.name)" $result | Out-File $Output -Append; } } }
Thanks in advance !
Sunday, June 14, 2020 6:40 PM
All replies
-
The Below PowerShell script loops through all the sites under a site collection and all the lists under each web and all the items under each list and generates 2 separate reports, one to hold the in-progress workflow details and the other to hold the completed workflow details.
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm $LogFile = ".\WorkflowDetailsPatch-$LogTime.rtf" # Add SharePoint PowerShell Snapin if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Microsoft.SharePoint.Powershell } $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent Set-Location $scriptBase write-host "TESTING FOR LOG FOLDER EXISTENCE" -fore yellow $TestLogFolder = test-path -path $scriptbase\Logs if($TestLogFolder) { write-host "The log folder already exist in the script location" -fore yellow $clearlogfolder = read-host "Do you want to clear the log folder (y/n)" if($clearlogfolder -eq 'y') { write-host "The user choosen to clear the log folder" -fore yellow write-host "Clearing the log folder" -fore yellow remove-item $scriptbase\Logs\* -recurse -confirm:$false write-host "Log folder cleared" -fore yellow } else { write-host "The user choosen not to clear the log files" -fore yellow } } else { write-host "Log folder does not exist" -fore yellow write-host "Creating a log folder" -fore yellow New-Item $Scriptbase\Logs -type directory write-host "Log folder created" -fore yellow } #moving any .rtf files in the scriptbase location $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf if($FindRTFFile) { write-host "Some old log files are found in the script location" -fore yellow write-host "Moving old log files into the Logs folder" -fore yellow foreach($file in $FindRTFFile) { move-item -path $file -destination $scriptbase\logs } write-host "Old log files moved successfully" -fore yellow } start-transcript $logfile Function WorkflowReports() { $output = $scriptbase + "\" + "InProgressWorkflows.csv" "SiteCollection" + "," + "WebURL" + "," + "List" + "," + "ItemName" + "," + "ItemGUID" + "," + "WorkflowInstanceID" | Out-File -Encoding Default -FilePath $Output; $output1 = $scriptbase + "\" + "OtherWorkflows.csv" "SiteCollection" + "," + "WebURL" + "," + "List" + "," + "ItemName" + "," + "ItemGUID" + "," + "WorkflowInstanceID" | Out-File -Encoding Default -FilePath $Output1; Write-host "Getting workflow report" -fore magenta $SiteCollectionURL = read-host "Enter site collection URL " $siteCollection = get-spsite $SiteCollectionURL -ea silentlycontinue if($SiteCollection -ne $null) { foreach($web in $SiteCollection.allwebs) { $lists = $web.lists foreach($list in $lists) { foreach($item in $list.items) { foreach($workflow in $item.workflows) { if($workflow.iscompleted -eq $false) { $SiteCollectionURL + "," + $web.url + "," + $list.Title + "," + $workflow.ItemName + "," + $workflow.ItemGUID + "," + $workflow.InstanceId | Out-File -Encoding Default -Append -FilePath $Output; } else { $SiteCollectionURL + "," + $web.url + "," + $list.Title + "," + $workflow.ItemName + "," + $workflow.ItemGUID + "," + $workflow.InstanceId | Out-File -Encoding Default -Append -FilePath $Output1; } } } } } Write-host "Reports generated and available at the script location " -fore green } else { write-host "Invalid site collection.... please check the URL...." -fore red } } WorkflowReports write-host "" write-host "SCRIPT COMPLETED" -fore green stop-transcript
Below article for your reference:
Thanks & Regards,
sharath aluri
Sunday, June 14, 2020 8:54 PM -
Hi MS.Chinn,
Here is the sample PowerShell script modified based on your original script:
# Parameters $Output="C:\Workflows.csv" $SiteCollectionURL = "http://sharepoint/ps" # Output File $SiteCollection = get-spsite $SiteCollectionURL "Site `t List `t ListItem `t Workflow Status `t Workflow Name " | out-file $output foreach($web in $SiteCollection.allwebs) { $lists = $web.lists foreach($list in $lists){ foreach($item in $list.items) { foreach($workflow in $item.workflows) { $result ="$($web.url) `t $($list.Title) `t $($workflow.ItemName)`t $($workflow.InternalState) `t $($workflow.ParentAssociation.name)" $result | Out-File $Output -Append; } } } } write-host "Report Generated" -fore green
Best regards,
Chelsea Wu
Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
SharePoint Server 2019 has been released, you can click here to download it.
Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.- Proposed as answer by Julie WangMicrosoft contingent staff Wednesday, June 17, 2020 8:07 AM
Monday, June 15, 2020 8:08 AM -
Hi,
Please remember to update this thread if you have any progress.
Thank you for your understanding.
Best regards,
Chelsea WuPlease remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
SharePoint Server 2019 has been released, you can click here to download it.
Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.Friday, June 19, 2020 7:02 AM