As an Admin, you can also manage flows by running Power Apps cmdlets for administrators. Please make sure you have followed the instructions to complete the installation if you have not done it before.
Fixing permissions for one flow
You will need the environment name and flow name (a GUID).
Run the Get-AdminFlowOwnerRole
cmdlet with environment name and flow name to get the list of users and their roles. This will enable you to verify the current permissions set for the flow.
To assign a co-owner to a flow, run Set-AdminFlowOwnerRole
with the AAD principal object id of the new owner
Set-AdminFlowOwnerRole -EnvironmentName <env name> -FlowName <flow name> -PrincipalType User -RoleName CanEdit -PrincipalObjectId <new owner object id>
NOTE
You can get the AAD principal object id of a user by running Get-AzureADUser cmdlet (which is from AzureAD module).
Run Get-AdminFlowOwnerRole again to verify the new owner is in the list.
Fixing permissions for flows created by a particular user
Get a list of flows created by a given user by running the following cmdlet, and then apply the above section to fix every flow on the list.
Get-AdminFlow -EnvironmentName <env name> -CreatedBy <user AAD object id>
Listing all orphaned flows in an environment
To get all flows that do not have valid users, loop through all flows in one environment, and verify there is at least one owner or co-owner that exists in AAD. The following script provides an example:
$env = "<your environment name>"
$flows = Get-AdminFlow -EnvironmentName $env
foreach ($flow in $flows)
{
$hasValidOwner = $false
$permissions = Get-AdminFlowOwnerRole -EnvironmentName $env -FlowName $flow.FlowName
foreach ($permission in $permissions)
{
$roleType = $permission.RoleType
if ($roleType.ToString() -eq "Owner" -or $roleType.ToString() -eq "CanEdit")
{
$userId = $permission.PrincipalObjectId
$users = Get-AzureADUser -Filter "ObjectId eq '$userId'"
if ($users.Length -gt 0)
{
$hasValidOwner = $true
break
}
}
}
if ($hasValidOwner -eq $false)
{
$flow
}
}
You can also inject the Set-AdminFlowOwnerRole
cmdlet to assign a co-owner for each flow that does not have a valid owner.