Wednesday, 13 September 2017

Inventory of SharePoint workflow

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
$outputFile = Read-Host "Filename and location (i.e. D:\Scripts\WorkflowInstances.csv)"

$farm = [Microsoft.SharePoint.Administration.SPFarm]::local
$websvcs = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
$webapps = @()

$outputHeader = "Url;List;Workflow;Running Instances" > $outputFile

foreach ($websvc in $websvcs) {

    foreach ($webapp in $websvc.WebApplications) {
  foreach ($site in $webapp.Sites) {
   foreach ($web in $site.AllWebs) {
    foreach ($List in $web.Lists) {
     foreach ($workflow in $List.WorkflowAssociations) {
      $output = $web.Url + ";" + $List.Title + ";" + $workflow.Name + ";" + $workflow.RunningInstances
      Write-Output $output >> $outputFile
    }}
    }
   }
  }
 }
$Web.Dispose();
$site.Dispose();

No comments:

Post a Comment