question

Viddy9 avatar image
0 Votes"
Viddy9 asked VenkySetty-6453 answered

Powershell Script to output all types of workflows in a Farm

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

office-sharepoint-server-administration
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@BenjaminLee-0319

Would you tell me whether your issue has been resolved or have any update ?
I am looking forward to your reply.

Thanks,
Echo Du

0 Votes 0 ·
VenkySetty-6453 avatar image
0 Votes"
VenkySetty-6453 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EchoDu-MSFT avatar image
0 Votes"
EchoDu-MSFT answered

@ 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.





r1.png (6.9 KiB)
r2.png (24.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sharatha avatar image
0 Votes"
sharatha answered BenLee-9163 commented

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,

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Sharatha, I get an output here but it doesnt appear to indicate if there is a workflow just all the libraries within the site. The other scripts here still do not output the 2010 workflows in powershell that I know are setup. For some reason they are being hidden from the results

0 Votes 0 ·