Tuesday, March 28, 2023

Powershell Script to export all active workflows in a web application to a CSV file

Here is a working example of exporting a list of all active workflows in a web application 


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue


$webApp = Get-SPWebApplication "http://your webapp url"


$csvFile = "<path to export folder>\workflows-active.csv" 


$results = @()


foreach ($site in $webApp.Sites) {

    foreach ($web in $site.AllWebs) {

     if ($web.WorkflowAssociations.Count -gt 0) {

            $webObj = New-Object PSObject -Property @{

                "Title" = $web.Title

                "Url" = $web.Url

                "Workflows" = $web.WorkflowAssociations| where {$_.Enabled -eq $true} | Select-Object -ExpandProperty Name

            }

            $results += $webObj

        }

        # Get all the lists in the web

        $lists = $web.Lists

        foreach ($list in $lists) {

            # Get all the workflow associations for the list

            $workflowAssociations = $list.WorkflowAssociations | where {$_.Enabled -eq $true}

            foreach ($workflowAssociation in $workflowAssociations) {

                # Create an object to store the workflow details

                $workflowObj = New-Object PSObject -Property @{

                    "SiteCollection" = $web.Site.Url

                    "Web" = $web.Title

                    "List" = $list.Title

                    "ListURL" = $web.Url + "/" + $list.RootFolder.Url

                    "WorkflowName" = $workflowAssociation.Name

                    "IsActive" = $workflowAssociation.Enabled

                }

                # Add the workflow object to the results array

                $results += $workflowObj

            }

        }

        $web.Dispose()

    }

    $site.Dispose()

}


$results | Export-Csv -Path $csvFile -NoTypeInformation


No comments:

Post a Comment