Sometimes you need to find flows created by a specific user as a Power Platform Adminstrator, for example if the user is no longer in the organization. In the admin center for Power Platform, it is possible to list the flows (or the Power Apps) in an environment, but the functionality is not very good. The search function only works on the flows shown in the display, so you need to click “load more” multiple times to be able to search all the flows.
I created a PowerShell script, find-flow-by-user.ps1, which helps administrators find all Power Automate flows created by a specific user in a Power Platform environment.
Script Overview
The find-flow-by-user.ps1 script performs the following tasks:
- Checks if the required PowerShell module is installed and installs it if necessary.
- Logs into the Power Platform environment.
- Lists all environments.
- Exports flow details to a CSV file.
- Finds all flows created by a specific user.
Prerequisites
Before running the script, ensure you have the following:
- PowerShell installed on your machine.
- Power Platform Administrator privileges.
- The
Microsoft.PowerApps.Administration.PowerShellmodule.
The script
Here is the script code. It shows how to find all the flows by a specified user. I have also added comments in the code that shows how you can find the userId, how you can assign another user as an owner to the flow (Set-FlowOwnerRole) and more.
### Find all Power Automate flows created by a specific user in a Power Platform environment
param (
[string]$userId, # The user ID of the user you want to find flows for
[string]$environmentName # The name of the environment you want to search in
)
### To find the userId, you can use the AzureAD module: ###
# Install-Module AzureAD
# Connect-AzureAD
# Get-AzureADUser -ObjectId [email]
#### If you need to find the environment name, you can use the PowerApps module: ###
# For example: Get-AdminPowerAppEnvironment *default*
# Check if the module is already installed
if (-not (Get-Module -ListAvailable -Name Microsoft.PowerApps.Administration.PowerShell)) {
Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Force
}
# Log in (you need to be a Power Platform Administrator via PIM)
Add-PowerAppsAccount
# Export to CSV file
$flows = Get-AdminFlow -EnvironmentName $environmentName
### If you want to export to a csv file add: | Export-Csv -Path "C:\dev\PowerAutomateFlows.csv" -NoTypeInformation
# Find all flows created by a specific user
foreach ($flow in $flows) {
# Get flow details, including the owner
$flowDetails = Get-AdminFlow -EnvironmentName $environmentName -FlowName $flow.FlowName
# Check if the user email is in the owner details
if ($flowDetails.displayName -and $flowDetails.CreatedBy -and $flowDetails.CreatedBy.userId -eq $userId) {
Write-Output "Flow Name: $($flow.DisplayName), Flow ID: $($flow.FlowName)"
}
}
### If you want to add another user as the owner of the flow, you can use the Set-FlowOwnerRole cmdlet ###
# Set-FlowOwnerRole -EnvironmentName $environmentName -FlowName [YourFlowID] -PrincipalType User -RoleName CanEdit -UserId $userId