none
Looking for templates for share in documenting workflows by site RRS feed

  • Question

  • Looking for helpful templates for share that I can document and take an inventory of all of our workflows in SharePoint by site.

    Thanks,

    dgreene

    Wednesday, September 4, 2019 8:56 PM

All replies

  • You mean you need all your workflows from a SharePoint Site ? If that was the below script will get you list of all workflows under the site in a .CSV file.

    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)  
    {  
      
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"  
    }  
      
    $results = @()  
    $siteColl =  "http://sharepoint.starkindustries.com/it"  
       
    $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 -eq $true)  
                {  
                    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! === === === === === === == "  

    Below articles for your reference:

    https://www.c-sharpcorner.com/article/find-all-workflows-in-sharepoint-using-powershell/

    https://social.technet.microsoft.com/Forums/ie/en-US/42020beb-5e36-49bc-bd76-d1ef93500a43/powershell-script-to-retrieve-all-workflows-from-a-farm?forum=sharepointadmin

    Thanks & Regards,


    sharath aluri

    Wednesday, September 4, 2019 9:32 PM
  • Hi dgreene,

    From your description, my understanding is that you want to list all workflows in a site collection. Please kindly correct me if I misunderstand it.

    You could try the following script to achieve this:

    If ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)  
    { 
        Add-PSSnapin "Microsoft.SharePoint.PowerShell" 
    } 
     
    Function WriteWFDetails($wfAssociations, $wfType, $listTitle, $OutputFile, $includePreviousVersions)  
    { 
        if($includePreviousVersions) { 
            $wfAssociations = ($wfAssociations | Sort-Object Name) 
        } 
        else { 
            $wfAssociations = ($wfAssociations | ?{-Not ($_.Name -like "*Previous Version*")} | Sort-Object Name) 
        } 
        foreach($wfAssociation in $wfAssociations) { 
            $record =",$wfType,`"$($listTitle)`",`"$($wfAssociation.Name)`",`"$($wfAssociation.TaskListTitle)`",`"$($wfAssociation.HistoryListTitle)`"," 
            $record += "$($wfAssociation.RunningInstances),$($wfAssociation.Created),$($wfAssociation.Modified)" 
            Add-Content $OutputFile $record 
        } 
    } 
     
    Function AllWorkflows($siteUrl, $OutputFile, $includePreviousVersions) 
    { 
        $siteColl  = Get-SPSite $siteUrl 
        Set-Content $OutputFile "WebUrl,SiteWFCount,ListWFCount" 
        Add-Content $OutputFile ",SiteWF or ListWF or CTWF?,ListName or List/CTName,WorkflowName,TaskList,HistoryList,RunningInstances,Created,Modified" 
     
        foreach($web in $siteColl.AllWebs) 
        { 
            $webUrl = if($web.IsRootWeb) { "$($web.Url) -- RootWeb" } else {  $web.Url } 
     
            if($includePreviousVersions) { 
                $siteWFCount = $web.WorkflowAssociations.Count 
                $contWFCount = $web.ContentTypes.WorkflowAssociations.Count 
                $listWFCount = $web.Lists.WorkflowAssociations.Count 
            } 
            else { 
                $siteWFCount = ($web.WorkflowAssociations | ? {-Not ($_.Name -like "*Previous Version*")}).Count 
                $contWFCount = ($web.ContentTypes.WorkflowAssociations | ? {-Not ($_.Name -like "*Previous Version*")}).Count 
                $listWFCount = ($web.Lists.WorkflowAssociations | Select Name | ? {-Not ($_.Name -like "*Previous Version*")}).Count 
            } 
     
            if($listWFCount -gt 0 -or $siteWFCount -gt 0 -or $contWFCount -gt 0) { 
                $record = "`"$webUrl`",$siteWFCount,$listWFCount" 
                Add-Content $OutputFile $record; 
             
                WriteWFDetails $web.WorkflowAssociations "SiteWF" "" $OutputFile $includePreviousVersions 
                if($contWFCount -gt 0) { 
                    WriteWFDetails $web.ContentTypes.WorkflowAssociations "CTWF" "" $OutputFile $includePreviousVersions 
                } 
                foreach($list in $web.Lists) 
                { 
                    if($list.WorkflowAssociations.Count -gt 0) { 
                        WriteWFDetails $list.WorkflowAssociations "ListWF" $list.Title $OutputFile $includePreviousVersions 
                    } 
                    foreach($ct in ($list.ContentTypes | ? {$_.WorkflowAssociations.Count -gt 0})) { 
                        WriteWFDetails $ct.WorkflowAssociations "ListCTWF" "$($list.Title)/$($ct.Name)" $OutputFile $includePreviousVersions 
                    } 
                }             
            } 
            $web.Dispose() 
        } 
        $siteColl.Dispose() 
    } 
     
    #parameter 3 - pass $TRUE to include previous workflow versions 
    AllWorkflows "<your site collection url here>" "C:\Temp\WorkflowReport.csv" $FALSE 

    References:

    https://gallery.technet.microsoft.com/office/List-of-all-workflows-in-a-ffa0b355

    https://www.c-sharpcorner.com/article/find-all-workflows-in-sharepoint-using-powershell/

    Best Regards,

    Michael Han


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, September 5, 2019 6:32 AM
  • Hi,

    How are things going? Is there any update on your issue?

    Please remember to mark the reply as an answer if it helps. 

    Have a nice day!

    Best Regards, 

    Michael Han 

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, September 13, 2019 8:16 AM