Skip to content

Find All Power Automate Flows Using SharePoint or OneDrive with PowerShell

Billy Peralta

1 min read

Find All Power Automate Flows Using SharePoint or OneDrive with PowerShell

Topics: O365, M365, SharePoint Online, Power Automate, PowerShell

Ever wondered how to search for Power Automate workflow based on the action they use?

Here is a brief tutorial on how to create a script that will look for Power Automate Workflows that uses SharePoint or OneDrive Actions

Requirements

Before you can run Script below you need the follower

  • PowerShell
  • “Microsoft.PowerApps.Administration.PowerShell” Module
  • “Microsoft.PowerApps.PowerShell” Module
  • “AzureAD” Module”

Installation of needed modules

To install all the Modules we will need, just run the following line

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber
Install-Module -Name AzureAD

Login in M365

To allow us to access our M365 Tenant we need to run the following command

Note: You need to login twice because youll be logging in to Power Automate Site and to Azure AD site.

Note #2: The reason why we need to login to Azure AD because we will use that to get the display name of our users later

Add-PowerAppsAccount
Connect-AzureAD

After getting Authenticated, kindly run the follow script to start getting all Power Automate workflow that uses SharePoint related Action(or could also be OneDrive related Actions)

$environments = Get-FlowEnvironment #This is to get all available Environment in our Power Automte Tenant

$csvVariable = @()
foreach($environ in $environments.EnvironmentName) #Cycle to all Environments
{

$flows = Get-AdminFlow –EnvironmentName $environ 
    foreach ($flow in $flows) #Loop to each PowerAutomate workflow Available
    {
        $WFDetails = $flow | Get-AdminFlow
        #shared_sharepointonline is the reference for searchin any related SharePoint action. If you want to search for Onedrive actions, just change it to "shared_onedriveforbusiness"
        if([bool]($WFDetails.Internal.properties.connectionReferences -match "shared_sharepointonline")) 
        {
            $obj = New-Object -TypeName psobject

            $obj | Add-Member -MemberType NoteProperty -Name "Environtment" -Value $flow.EnvironmentName
            $obj | Add-Member -MemberType NoteProperty -Name "FlowID" -Value $flow.FlowName
            $obj | Add-Member -MemberType NoteProperty -Name "FlowDisplayName" -Value $flow.DisplayName
            $obj | Add-Member -MemberType NoteProperty -Name "FlowAddress" -Value   $flow.Internal.id
            $obj | Add-Member -MemberType NoteProperty -Name "Enabled" -Value $flow.Enabled
            $obj | Add-Member -MemberType NoteProperty -Name "FlowCreated" -Value $flow.CreatedTime
            $obj | Add-Member -MemberType NoteProperty -Name "LastModified" -Value $flow.LastModifiedTime

            #Get-AzureADUser helps us to get the Display Name of the Owner of the Workflow because PowerAutomate only holds ObjectID of the user unfortunately.
            $obj | Add-Member -MemberType NoteProperty -Name "Creator" -Value (Get-AzureADUser -ObjectId  $flow.CreatedBy.objectId).DisplayName
         


            $owner = Get-AdminFlowOwnerRole –EnvironmentName $environ -FlowName $flow.FlowName 
            $varOwner = @()
            $varGroupOwner = @()

            #Seperating Group Owner to User Owners|
            foreach ($singleOwner in $owner)
            {
                switch ($singleOwner.PrincipalType)
                {
                    User {
                            try {
                                
                                $varOwner += (Get-AzureADUser -ObjectId $singleOwner.PrincipalObjectId)
                            }
                            catch [System.Net.WebException],[System.IO.IOException] {
                            }
                        }
                    Group 
                        {
                            #Note we are searching for Group because we can also assign a Group as an Owner of the Power Automate
                            try {
                                $varGroupOwner += (Get-AzureADGroup -ObjectId $singleOwner.PrincipalObjectId)
                            }
                            catch [System.Net.WebException],[System.IO.IOException] {
                            }
                        }
                }
            }

            
            $tempArray = $varOwner | Foreach {"$($_.DisplayName)"} 
            $obj | Add-Member -MemberType NoteProperty -Name "OwnerUsers" -Value  ($tempArray -join ',')
            $tempArray = $varGroupOwner | Foreach {"$($_.DisplayName)"} 
            $obj | Add-Member -MemberType NoteProperty -Name "OwnerGroups" -Value  ($tempArray -join ',')
               
            $csvVariable += $obj;
        }
    }
}


#Create a CSV file out of our results
$csvVariable | Export-Csv '.\WorkflowResults.csv' -Force

An inventory like this is the starting point for keeping SharePoint automation supportable. Knowing who owns each flow matters most when that person leaves; my post on Power Automate governance for SharePoint covers what breaks and how to set up ownership so flows keep running. If you want help putting governance around SharePoint and the flows that depend on it, see my SharePoint governance consulting page.

Need help building or stabilizing Power Apps connected to SharePoint?

I help organizations design Power Apps and Power Automate solutions that are maintainable, governed, and easier to support after launch.

16+ years experience Microsoft certified Government & enterprise

Free SharePoint planning resource

Solving the technical issue is only part of the Microsoft 365 problem.

Use the checklist to review the governance, permission, ownership, and support decisions that often determine whether a SharePoint solution succeeds long term.

Download the Checklist

Billy Peralta

SharePoint architect & Microsoft 365 consultant • 16+ years of experience

If you have questions about your SharePoint environment, feel free to reach out.

LinkedIn GitHub

Continue Reading

View all posts