This script genenrates report of all list workflows in all the site collections or a given site collection url. It captures the below properites

The user must be SCA at site collection level to access all the subsites of a site collection.

 1. Web Id

 2. Web Url

 3. Web Name

 4. List title

 5. Workflow Name

 6. Tasks list of the workflow

 7. WF History list of the workflow

 8. Create date

 9. WF last modified date

 

PowerShell
Edit|Remove
# In SharePoint Online you must be site collection administrator to access all the subsites 
# Even you are SPAdmin/GlobalAdmin you may not get access to all the sites/subsites  
 
Add-Type -Path "Microsoft.SharePoint.Client.dll"   
Add-Type -Path "Microsoft.SharePoint.Client.Runtime.dll" 
Add-Type -Path "Microsoft.Online.SharePoint.Client.Tenant.dll"  
 
$orgName = "<organization name>" 
$admin = "<your account>"  
$password = ConvertTo-SecureString "<password>" -AsPlainText -Force  
$adminUrl = "https://$orgName-admin.sharepoint.com" 
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin$password)  
 
 
Function GetWorkflowsInEachWeb ($siteCollectionUrl$url$OutputFile) 
{ 
    try { 
        $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)  
        $ctx.Credentials = $credentials 
        $web = $ctx.Web  
        $ctx.Load($web)      
        $ctx.Load($web.Webs) 
        $ctx.Load($web.Lists)     
        $ctx.ExecuteQuery() 
     
        Write-host $web.Url         
        $record = "$($web.Id),`"$($web.Url)`",`"$($web.Title)`"," 
         
        foreach($list in $web.Lists) {         
            $ctx.Load($list.WorkflowAssociations)     
            $ctx.ExecuteQuery() 
            $i = 0 
            foreach($wfAssociation in $list.WorkflowAssociations) {  
                if($i -ne 0) { $record = ",,," } 
                $record +"`"$($list.Title)`",`"$($wfAssociation.Name)`",`"$($wfAssociation.TaskListTitle)`","  
                $record +"`"$($wfAssociation.HistoryListTitle)`",$($wfAssociation.Created),$($wfAssociation.Modified)"  
                Add-Content $OutputFile $record 
                $i++ 
            }  
        } 
 
        foreach($subweb in $web.Webs) {         
            GetWorkflowsInEachWeb $siteCollectionUrl $subweb.Url $OutputFile 
        } 
    } 
    catch { Write-Host "Access Denied" } 
} 
 
 
Function GetAllWorkflows($OutputFile)  
{  
    #Write CSV separated file header  
    Set-Content $OutputFile "WebId,Url,Name,ListTitle,WorkflowName,TaskList,HistoryList,Created,Modified" 
 
    $t_ctx = New-Object Microsoft.SharePoint.Client.ClientContext($adminUrl) 
    $t_ctx.Credentials = $credentials 
    $tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($t_ctx) 
    $props = $tenant.GetSiteProperties(0, $true) 
    $t_ctx.Load($props) 
    $t_ctx.ExecuteQuery() 
    #if you want to limit to a specific site collection. 
    #$props = $props | ? {$_.Url -eq "<your site collection url here>"} 
    foreach($prop in $props) {         
       GetWorkflowsInEachWeb $prop.Url $prop.Url $OutputFile 
    } 
} 
 
GetAllWorkflows "C:\Temp\SPO-AllWorkflows.csv"