Windows PowerShell  

Exporting Power Automate Flow Details with PowerShell

Monitoring and auditing Microsoft Power Automate flows can be challenging, especially in environments with multiple users and flows. PowerShell provides a powerful way to extract detailed information about flows, their status, and recent run history. In this article, we will explore a PowerShell script that connects to PowerApps, retrieves all flows in your tenant, and exports the details into a CSV report.

PowerShell Script Overview

The following script does the heavy lifting:

  
    # Login to PowerApps account
Add-PowerAppsAccount

# Define the output CSV file path
$ReportFilePath = "C:\Users\DELL\Desktop\Reportoutput\Trail Folder\McQPartnersFlow-26-2-2024.csv"

# Retrieve all flows
$AllFlows = Get-AdminFlow

# Initialize collection for flow details
$AllFlowDetails = @()

ForEach ($SingleFlow in $AllFlows) {
    try {
        # Retrieve detailed information about the flow
        $FlowMetadata = Get-AdminFlow -FlowName $SingleFlow.FlowName -EnvironmentName $SingleFlow.EnvironmentName

        # Retrieve the most recent run status and start date
        $LatestFlowRun = Get-FlowRun -FlowName $SingleFlow.FlowName | Sort-Object StartTime -Descending | Select-Object -First 1

        # Create a custom object with the flow's properties
        $FlowRecord = [PSCustomObject]@{
            DisplayName        = $FlowMetadata.DisplayName
            Enabled            = $FlowMetadata.Enabled
            FlowName           = $FlowMetadata.FlowName
            UserType           = $FlowMetadata.UserType
            CreatedTime        = $FlowMetadata.CreatedTime
            LastModifiedTime   = $FlowMetadata.LastModifiedTime
            CreatedBy          = $FlowMetadata.CreatedBy
            EnvironmentName    = $FlowMetadata.EnvironmentName
            Connectors         = ($FlowMetadata.Internal.properties.connectionReferences.PSObject.Properties | ForEach-Object { $_.Value.DisplayName }) -join " | "
            LastRunStatus      = if ($LatestFlowRun) { $LatestFlowRun.Status } else { "Not Available" }
            LastRunDate        = if ($LatestFlowRun) { $LatestFlowRun.StartTime } else { "Not Available" }
        }

        # Add the flow detail to the collection
        $AllFlowDetails += $FlowRecord
    } catch {
        Write-Host "Error processing flow: $($SingleFlow.DisplayName). Error: $_" -ForegroundColor Red

        # Add an entry with error information
        $AllFlowDetails += [PSCustomObject]@{
            DisplayName        = $SingleFlow.DisplayName
            Enabled            = $SingleFlow.Enabled
            FlowName           = $SingleFlow.FlowName
            UserType           = $SingleFlow.UserType
            CreatedTime        = $SingleFlow.CreatedTime
            LastModifiedTime   = $SingleFlow.LastModifiedTime
            CreatedBy          = "Error retrieving details"
            EnvironmentName    = $SingleFlow.EnvironmentName
            Connectors         = "Error retrieving details"
            LastRunStatus      = "Error"
            LastRunDate        = "Error"
        }
    }
}

# Export to CSV
$AllFlowDetails | Export-Csv -Path $ReportFilePath -NoTypeInformation -Encoding UTF8

Write-Host "Flow processing completed. Results exported to: $ReportFilePath" -ForegroundColor Green
  

What Does This Script Do?

  • Authentication: Connects to PowerApps using Add-PowerAppsAccount .

  • Flow Retrieval: Fetches all flows in the tenant with Get-AdminFlow .

  • Details Extraction: Collects metadata such as display name, creation date, last modified time, and connectors used.

  • Run History: Retrieves the latest run status and timestamp for each flow.

  • Error Handling: Ensures flows with issues are still logged in the report with error messages.

  • Export: Saves all flow details into a CSV file for further analysis and reporting.

Why Is This Useful?

Organizations often need visibility into their Power Automate flows for compliance, governance, and troubleshooting purposes. This script helps administrators:

  • Audit flow ownership and creation dates.

  • Track when flows were last modified.

  • Identify which connectors are being used across environments.

  • Check recent run statuses to detect failing or inactive flows.

Happy Coding!!! Keyur Pandya