Powershell Script to output all types of workflows in a Farm

Viddy9 61 Reputation points
2020-10-12T14:34:59.837+00:00

I have run multiple scripts found on other technet articles to locate all 2010, 2013 & SharePoint designer workflows. The scripts run ok and output results.

The problem is:

I am looking at multiple workflows in my sites that are not appearing on any of the scripts output I have tried which Is leading me to think it is not outputting all of the workflows correctly. Why would this be happening? and does anyone have an uber script that will pull everything across all of the technologies with SharePoint workflows. Thanks

SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,934 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Sharath Kumar Aluri 3,071 Reputation points
    2020-10-12T21:31:29.933+00:00

    Try with the below scripts this should give you the accurate results for 2010 & 2013 workflows. If you miss any might be default reusable workflows which you can ignore them.

    #Get SP 2010 Workflows
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)  
      {  
    
          Add-PSSnapin "Microsoft.SharePoint.PowerShell"  
      }  
    
      $results = @()  
      $siteColl =  "http://sp/sites/dev"  
    
      $site = Get-SPSite -Identity $siteColl -Limit All  
      try  
      {   
          foreach ($myWeb in $site.AllWebs)  
          {  
              Write-Host "Looking in Web: " $myWeb.Url -ForegroundColor Red  
              foreach($list in $myWeb.Lists)  
              {  
                  if ($list.WorkflowAssociations)  
                  {  
                      Write-Host $list.Title -ForegroundColor Blue  
                      foreach ($wflowAssociation in $list.WorkflowAssociations)  
                      {  
                          $RowDetails =  @{            
                            "List Name"         = $wflowAssociation.ParentList.Title  
                            "Workflow Name"     = $wflowAssociation.InternalName  
                            "Running Instances" = $wflowAssociation.RunningInstances  
                            "Created On"        = $wflowAssociation.Created  
                            "Modified On"       = $wflowAssociation.Modified  
                            "Parent Web"        = $wflowAssociation.ParentWeb  
                            "Task List"         = $wflowAssociation.TaskListTitle  
                            "History List"      = $wflowAssociation.HistoryListTitle                   
                          }  
    
                          $results += New-Object PSObject -Property $RowDetails  
                      }            
                  }  
    
              }  
          }  
    
          $myFileName = [Environment]::GetFolderPath("Desktop") + "\workflowList.csv"  
          $results | Select-Object "List Name", "Workflow Name", "Running Instances", "Created On","Modified On","Parent Web", "Task List","History List"    | export-csv -Path $myFileName -NoTypeInformation  
    
      }  
    
      catch   
      {   
          $e = $_.Exception   
          $line = $_.InvocationInfo.ScriptLineNumber   
          $msg = $e.Message   
          Write-Host –ForegroundColor Red "Caught Exception: $e at $line"   
          Write-Host $msg   
          Write-Host "Something went wrong"  
      }   
    
      Write-Host " === === === === === Completed! === === === === === === == " 
    

    For SP 2013 workflows use the below script:

    # Get SP 2013 workflows
    
     if ((Get-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue) -eq $null) {
       Add-PSSnapin 'Microsoft.SharePoint.PowerShell'
     }
     CLS
     $spAssignment = Start-SPAssignment
     $outputFile = 'C:\Temp\2013Workflows.csv'
     $output = '';
     $wfResults = @();
     $i = 0;
     Write-Host 'Searching 2013 Workflows ....' -NoNewline;
    
      $siteColl =  "http://sp/sites/dev" 
      $site = Get-SPSite -Identity $siteColl -Limit All
    
    
         # get the collection of webs
         foreach($spWeb in $site.AllWebs) {
           $wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spWeb)
           $wfsService = $wfm.GetWorkflowSubscriptionService()
           foreach ($spList in $spWeb.Lists) {
             $subscriptions = $wfsService.EnumerateSubscriptionsByList($spList.ID)
             foreach ($subscription in $subscriptions) {
               #$subscriptions.name
               #$subscriptions.PropertyDefinitions#._UIVersionString #_IsCurrentVersion
               $i++
               #excluding multiple version of the same workflow
               if (($spWeb.Url + $spList.Title + $subscriptions.Name) -ne $output) {
                 $output = $spWeb.Url + $spList.Title + $subscription.Name    
                 $wfID = $subscription.PropertyDefinitions["SharePointWorkflowContext.ActivationProperties.WebId"]        
                 $wfResult = New-Object PSObject;
                 $wfResult | Add-Member -type NoteProperty -name 'URL' -value ($spWeb.URL);
                 $wfResult | Add-Member -type NoteProperty -name 'ListName' -value ($spList.Title);
                 $wfResult | Add-Member -type NoteProperty -name 'wfName' -value ($subscription.Name);
                 $wfResult | Add-Member -type NoteProperty -name 'wfID' -value ($wfID);
                 $wfResults += $wfResult;
               }
               if ($i -eq 10) {Write-Host '.' -NoNewline; $i = 0;}
             }
           }
    
    
     }
     $wfResults | Export-CSV $outputFile -Force -NoTypeInformation
     Write-Host
     Write-Host 'Script Completed'
     Stop-SPAssignment $spAssignment  
    

    Thanks & Regards,


  2. Echo Du_MSFT 17,156 Reputation points
    2020-10-13T06:06:51.077+00:00

    @ BenjaminLee-0319

    1.You could try to execute the following script on the SharePoint server. This should list info on all the working workflow on the server.

     #Load SharePoint snap-in   
     Add-PSSnapin Microsoft.SharePoint.PowerShell   
     #Fetches webapplications in the farm   
     $WebApplications = Get-SPWebApplication -IncludeCentralAdministration       
     foreach($WebApplication in $WebApplications){   
          #Fetches site collections list within sharepoint webapplication   
          Write-Output ""   
          Write-host "Working on web application $($WebApplication.Url)" -ForegroundColor Green  
          $Sites = Get-SPSite -WebApplication $WebApplication -Limit All       
          foreach($Site in $Sites)  
          {        
              #Fetches information for each  site - old code   
              $site = Get-SPSite($Site.Url);  
              $site.AllWebs | foreach { $_.Lists | foreach { $_.WorkflowAssociations | foreach {   
                  write-host "Site:" $_.ParentWeb.Url ", List:" $_.ParentList.Title ", Workflow:" $_.Name  
                  Write-Output "=========="   
        } } }  
              $Site.Dispose()   
          }   
      }      
    

    31840-r1.png

    2.The below PowerShell script is to list all workflows from SharePoint 2013/2016 site collection using PowerShell

    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)    
    {    
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"    
    }    
    $site = Get-SPSite("http://sp/sites/echo");  
    $site.AllWebs | foreach { $_.Lists | foreach { $_.WorkflowAssociations | foreach {  
    write-host "Site:" $_.ParentWeb.Url ", List:" $_.ParentList.Title ", Workflow:" $_.Name -ForegroundColor Cyan   
    } } }  
    

    31847-r2.png

    Thanks,
    Echo Du

    =============

    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Walkingstar 1 Reputation point
    2021-06-25T13:35:34.363+00:00

    There are 3 types of workflow associations that can happen on SharePoint: 1. List associated workflows 2. Site associated workflows 3. Content type associated workflows.

    All the scripts above work just fine for list associated workflows. For Site's and Content type associated workflows, script will differ.
    For site associated workflows, something like this will show the results:
    foreach($site in $wa.sites)
    {
    foreach($web in $site.AllWebs)
    {
    $workflows = $web.WorkflowAssociations
    foreach($wf in $workflows)
    {
    if($wf.Name -notlike "Previous Version")
    {
    $web.url + "|" + " |" + $wf.Name >> Workflow-Enabled-Sites.txt
    }
    }
    }
    }

    For Content type associated workflows:

    I'm looking forward for an answer on this.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.