Export disabled PowerAutomate flows from all environments across Microsoft 365 Tenant

Straightforward PowerShell script designed to export all the PowerAutomate workflows turned-off in all the environments by utilizing PnP PowerShell

In the fast-paced world of data management and automation, the ability to export data efficiently is a skill highly required by professionals across various fields. Fortunately, PowerShell scripts offer a powerful solution to streamline this process, allowing users to extract and manipulate data with ease.

Here’s a simple PowerShell script that assists in exporting the list of all disabled (turned-off) Power Automate workflows across all environments within Microsoft 365 Tenant by utilising PnP PowerShell.

PnP PowerShell version used:2.4.63-nightly

Flow.Properties.State should be Stopped . This condition helps us to get the disabled PowerAutomate flows.

$siteurl = "https://<tenant>-admin.sharepoint.com"
Connect-PnPOnline $siteurl -Interactive
Write-Host "Execution Started..."
$environments = Get-PnPPowerPlatformEnvironment
Write-Output "Total environments: "$environments.length
If ($environments.length -gt 0) {
    $results = @()
    foreach ($env in $environments) {
        $flows = Get-PnPFlow -Environment $env.Name -AsAdmin | Where-Object {$_.properties.State -eq 'Stopped'}
        If($flows.length -gt 0){
            Write-Host $env.Properties.DisplayName " - " $flows.length " disabled flows found. Exporting flows"
            foreach($flow in $flows){
                $results += [pscustomobject][ordered]@{
                    EnvironmentID = $env.Name
                    Environment  = $env.Properties.DisplayName
                    FlowID = $flow.Name
                    FlowName = $flow.properties.DisplayName
                    Created = $flow.properties.CreatedTime
                    Modified = $flow.properties.LastModifiedTime
                    FlowStatus = $flow.properties.State
                    StoppedReason = $flow.properties.FlowSuspensionReason
                }
                
            }
        }else{
            Write-Host $env.Properties.DisplayName " - No disabled flows available for the current user!"
        }
        
    }
    $results | Export-Csv -Path "allenvironmentflows.csv" -NoTypeInformation
    Write-Host "Export Completed."
}

The above script executes and iterates all the environments in a Microsoft 365 Tenant and fetches only the disabled flows. Then it exports in to the csv file in current running path.

Note: The user who runs the script, should have access to all the environments. Other wise it returns an error says.

Shantha Kumar
Shantha Kumar
Articles: 297