Introduction
In this tutorial, we will learn about how we can get consolidated workflow reports from the SharePoint Online tenant using PowerShell CSOM and PnP PowerShell. This script will scan through all the sites in a tenant and will export all workflows associated with the lists into a CSV file.
Workflows report from SharePoint Online using PowerShell CSOM & PnP
Using the below PowerShell CSOM & PnP code, we can get all workflows from the SharePoint Online tenant,
Notes about the above code
- We must use the “Get-PnPTenantSite” to get all sites from the tenant, the other command “Get-PnPSite“, if we use this, it will give only the tenant admin site URL, like below.
- Similarly, in order to get all sites from the tenant, we can use the “Get-SPOSite” command as well. However, if you have .net framework mismatch version installed in your PowerShell – this command will not work, we will get an error like "Connect-SPOService : Method not found: ‘!!0[] System.Array.Empty()‘"
- If we use the above code as is this will export all workflows from the tenant. However, if we want to export all workflows from a particular site we can comment the foreach loop and just we need to call the function "Get-WorkflowAssociationsDeatilsForEachSiteInTenant" as below:
- Get-WorkflowAssociationsDeatilsForEachSiteInTenant -SPOSiteURL $siteURL -UserName $userName -Password $password | Export-Csv $downloadLocation
Now, let’s execute the above script.
- After the successful execution of the script, a CSV file with the name of "SPOTenantWorkflowReport.csv" will be created in the script location directory – however, you can change the download location to your desired location.
Now, let’s look at all workflows exported as CSV reports.
We can see in the CSV report, all workflows from the SharePoint Online tenant have been exported.
Prerequisites to execute the above script
You need to place the below two DLLs in your script directory "Dependency Files" folder as like below:
Install PnP PowerShell
To install the "SharePointPnPPowerShellOnline" we need to run the below PowerShell command which will install PowerShell Package Management and then install the PowerShell Modules from the PowerShell Gallery.
- (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/sharepoint/PnP-PowerShell/master/Samples/Modules.Install/Install-SharePointPnPPowerShell.ps1')
Change the value of the variables in the parameters section like below.
- #Parameters
- #$siteURL="https://globalsharepoint2019.sharepoint.com/sites/ModernTeamSiteTestByPnP"
- $adminUrl = "Your SPO Admin URL Like - https://globalsharepoint2019-admin.sharepoint.com/"
- $downloadLocation=$directoryPathForFileDownloadLocation +"\"+ "SPOTenantWorkflowReport.csv"
- $userName = "YourSPOUserName"
- $password = "YourSPOPassWord"
- $securePassword= $password | ConvertTo-SecureString -AsPlainText -Force
- #Parameters ends here.
Summary
In this article, we have learned how we can generate a workflow consolidated report from SharePoint Online tenant using the PowerShell CSOM and PnP.
Download
The above code can be downloaded from
here.