I am using the following PS and cannot delete an orphaned flow. It has been deleted from Power Automate however in the Power Platform Admin Center it still appears within Flows. This is am e-mail distribution Flow for Power BI paginated reports which I am BCC on so I know that the Flow is still active as I am receiving the communications in my Inbox.
# Specify the target environment name
$environmentName = 'Default-2e3ae2ce-642b-49a6-9f6b-2217d5a549ec'
# Specify the flow name or a partial match for the flow to be deleted
$flowNameToMatch = "Test - PA - MES Transactions Not Posted"
# Get all flows in the specified environment
$flows = Get-AdminFlow -EnvironmentName $environmentName
# Find the target flow by display name
$targetFlow = $flows | Where-Object {$_.DisplayName -like $flowNameToMatch}
# Check if the flow was found
if ($targetFlow) {
# Prompt for confirmation before deleting
$confirmation = Read-Host "Are you sure you want to delete the flow '$($targetFlow.DisplayName)' in environment '$environmentName'? (Y/N)"
if ($confirmation -ceq "Y") {
try {
# Attempt to delete the flow
Remove-AdminFlow -EnvironmentName $targetFlow.EnvironmentName -FlowName $targetFlow.FlowName
# Wait for a short period to allow the deletion to propagate (optional, but can help with immediate confirmation)
Start-Sleep -Seconds 5
# Verify if the flow is no longer present
$deletedFlow = Get-AdminFlow -EnvironmentName $environmentName | Where-Object {$_.FlowName -eq $targetFlow.FlowName}
if (-not $deletedFlow) {
Write-Host "Successfully deleted flow '$($targetFlow.DisplayName)' in environment '$environmentName'." -ForegroundColor Green
} else {
Write-Warning "Deletion of flow '$($targetFlow.DisplayName)' might have failed or the flow is still present."
}
}
catch {
Write-Error "An error occurred while trying to delete the flow: $($_.Exception.Message)"
}
} else {
Write-Host "Deletion of flow '$($targetFlow.DisplayName)' cancelled by user." -ForegroundColor Yellow
}
} else {
Write-Warning "No flow found matching the name '$flowNameToMatch' in environment '$environmentName'."
}