Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting Russia – Generate Workflow Reports in SharePoint
This articles outlines a way to generate workflow reports (in-progress workflows and completed workflows) using a PowerShell script in SharePoint 2013. Consider a situation wherever you configure a work flow for a list to alert you when a new item is added or there are any changes to an existing item. In this case workflow item would have a separate instance of work flow.
Consider a list with thousands of things, wherever it’s tedious to visualize the workflow status on every item manually, here PowerShell is helpful. The PowerShell script explained in this article loops through all the websites beneath a site collection and every one the lists beneath each web and all the items under each list and generates 2 separate reports, one to hold the in-progress work flow details and also the other to hold the completed workflow details.
The following piece of code generates the workflow reports:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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 } } |
And the following code is the complete code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
$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 |
I hope this tutorial works for you!
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options.
Print article | This entry was posted by Peter on April 29, 2015 at 4:42 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |