Tuesday, February 28, 2017

Find attached Workflows to a list in SharePoint 2013 using PowerShell

This Script will iterate through all the provided Site Collections and export the attached Workflows with a list in a CSV file. It will also generate a log file that contains the script execution logs.

It will export the following items.

1. Site URL
2. Web URL
3. List Name
4. Attached Workflows Count

1.Text file containing database names

Create text file with name “DB.txt” in the same directory where script file is present.
Write database names in “DB” file. 
Make it sure each name should be in new line and write End Point at the end as shown below.

2.Open SharePoint 2013 Management Shell

3.Change directory path

Then type ./ WorkflowFinder.ps1 and press enter key.

3. Results
2.       Result will be saved in “WorkflowFinder.csv” file which you can find in the same directory where your script file is located.
You can also track the complete log file (named WorkflowFinder -current date and time) which you can find in the same directory where your script file is located. 

Output CSV will look like this.

PowerShell Scipt

[code] $currentTime = Get-Date -Format o | foreach {$_ -replace ":", "."} New-Item $PSScriptRoot\WorkFlowFinder-$currentTime.txt -type file New-Item $PSScriptRoot\WorkFlowFinder.csv -type file -Force $SiteCollectionArray = Get-Content -Path $PSScriptRoot\SiteCollections.txt Start-Transcript -Path "$PSScriptRoot\WorkFlowFinder-$currentTime.txt" $UtilStartTime = "Utility Start Time: " $startTime = Get-Date -Format F $UtilStartTime + $startTime $outputFile = "$PSScriptRoot\WorkFlowFinder.csv" #Initialize Workflow Count variable $workflowcount = 0 $outputHeader = "Site URL" + "`t" + "Web Url" + "`t" +" List Name" + "`t" + " Total Items " > $outputFile #Write-Host $DbArray.Length foreach($siteCol in $SiteCollectionArray) { if($siteCol -ne "End Point") { $SPSite =Get-SPSite -Identity $siteCol foreach($SPWeb in $SPSite.AllWebs) { foreach($SPList in $SPWeb.Lists) { foreach($wf in $SPList.WorkflowAssociations) { if ($wf.Name -notlike "*Previous Version*") { $workflowcount += 1 } } #Write-Host $workflowcount if($workflowcount -gt 0) { $output = $SPSite.Url + "`t" + $SPWeb.Url + "`t" + $SPList.Title + "`t" + $workflowcount >> $outputFile Write-Output $output } $workflowcount = 0 } } } } $UtilEndTime = "Utility End Time: " $endTime = Get-Date -Format F $UtilEndTime + $endTime Stop-Transcript [/code]

No comments:

Post a Comment