How to export Flows and Flow connections using PowerShell

Export Flows and Connections in Office 365 using PowerShell.

Flows to the left of us. Flows to the right of us. Flows everywhere.

Flow is an amazing service with a great potential in a lot of organizations. I really like to talk about Flow with end users since it’s so easy for them to see the possibilities and what they can do with it.

Unleashing Flow in a large organization will undoubtedly result in a mass of Flows.  

As administrators we need to keep this mass of Flows in some sort of order. Even if we want to empower users with the possibility to create Flows at their own initiative we may need to enforce certain governance and be able to monitor what’s going on in our environment.

I personally like to use PowerShell for a lot of administrative tasks. And for that I need so be able to get or export a list of all Flows and connections created in our tenant.

There are several scenarios where this is useful.

  • Send information to users who have created Flows instead of targeting the whole organization.
  • Inform users who have used certain connections about potential risks, so they are aware and can mitigate those risks.
  • Understand which Flows a leaver had and possibly transfer those Flows to their manager.

Below you will find a script that export all Flows and all connections to two CSV files using PowerShell. Please note that you need to be a global admin to be able to run extract this information.

Import-module Microsoft.PowerApps.PowerShell
Import-module Microsoft.PowerApps.Administration.PowerShell
Import-Module AzureADPreview

# Get credentials and connect.
$cred = Get-Credential
Add-PowerAppsAccount -Username $cred.UserName -Password $cred.Password

Connect-AzureAD -Credential $cred

# Folder path for export.
$exportFolderPath = 'C:\temp\'


# Export all Flows.

# Get all flows.
$flows = Get-AdminFlow

$flowExport = [System.Collections.ArrayList]@();

# Loop through all flows to expand on the user property. 
foreach ($flow in $flows) {

    $custFlow = New-Object -TypeName psobject 

    $custFlow | Add-Member -MemberType NoteProperty -Name FlowName -Value $flow.FlowName
    $custFlow | Add-Member -MemberType NoteProperty -Name Enabled -Value $flow.Enabled
    $custFlow | Add-Member -MemberType NoteProperty -Name DisplayName -Value $flow.DisplayName
    $custFlow | Add-Member -MemberType NoteProperty -Name CreatedTime -Value $flow.CreatedTime
    $custFlow | Add-Member -MemberType NoteProperty -Name EnvironmentName -Value $flow.EnvironmentName
    $custFlow | Add-Member -MemberType NoteProperty -Name LastModifiedTime -Value $flow.LastModifiedTime

    # Get the email of the user who created the flow. 
    try {
        $user = Get-AzureADUser -ObjectId $flow.CreatedBy.userId
        $custFlow | Add-Member -MemberType NoteProperty -Name CreatedBy -Value $user.Mail
    } catch {
        $custFlow | Add-Member -MemberType NoteProperty -Name CreatedBy -Value 'NOT FOUND IN AAD'

    $flowExport.Add($custFlow) | Out-null

# Export to CSV.
$flowExport | Export-Csv -Path ($exportFolderPath + 'Flows1.csv') -Delimiter ',' -NoTypeInformation


# Export all Connections.

# Get all the connections.
$connections = Get-AdminPowerAppConnection

$connectionsExport = [System.Collections.ArrayList]@();

# Loop through the connections to expand on some of the properties.
foreach ($connection in $connections) {

    $custConnection = New-Object -TypeName psobject 
    $custConnection | Add-Member -MemberType NoteProperty -Name ConnectionId -Value $connection.ConnectionId
    $custConnection | Add-Member -MemberType NoteProperty -Name ConnectorName -Value $connection.ConnectorName
    $custConnection | Add-Member -MemberType NoteProperty -Name CreatedByEmail -Value $
    $custConnection | Add-Member -MemberType NoteProperty -Name Statuses -Value ($connection.Statuses.status -join ',')
    $custConnection | Add-Member -MemberType NoteProperty -Name CreatedTime -Value $connection.CreatedTime
    $custConnection | Add-Member -MemberType NoteProperty -Name DisplayName -Value $connection.DisplayName
    $custConnection | Add-Member -MemberType NoteProperty -Name LastModifiedTime -Value $connection.LastModifiedTime

    $connectionsExport.Add($custConnection) | Out-null


# Export to CSV.
$connectionsExport | Export-Csv -Path ($exportFolderPath + 'Connections1.csv') -Delimiter ',' -NoTypeInformation