Find All Power Automate Flows Using SharePoint or OneDrive with PowerShell
Billy Peralta
August 27, 2022 · 1 min read
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 latera
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 Planning a SharePoint migration or cleanup?
I help organizations assess SharePoint environments, clean up stale content, review permissions, and build practical migration roadmaps before moving to Microsoft 365.
Free SharePoint planning resource
Planning a file share to SharePoint migration?
Download the SharePoint Migration & Governance Readiness Checklist and review scope, ROT cleanup, permissions, governance, and adoption before you move another folder.
Download the ChecklistBilly Peralta
SharePoint & Microsoft 365 Specialist • 16+ Years Experience
If you have questions about your SharePoint environment, feel free to reach out.
Planning a SharePoint migration or cleanup?
I help organizations assess SharePoint environments, clean up stale content, review permissions, and build practical migration roadmaps before moving to Microsoft 365.