I have to check the last execution time of all the cloud flows in my organization. Currently, I can use "Get-Adminflow" command in PowerShell to export all flows in my org. However, the output of this command only show columns like FlowName, CreateTime, CreateBy that can't meet my requirement. Due to this issue, I use another PowerShell command, Get-FlowRun, to retrieve the last execution record of every flow in my org. However, after I use this command, I can only see the last execution time and status of the flows that I owe and others share with me, other flows of these two columns remain empty.
Besides, I have the Power Platform administrator authority and Power Automate Premium for my account
Is there any suggestion that how can I fix this issue? Thanks a lot.
My PowerShell command:
Import-Module Microsoft.PowerApps.Administration.PowerShell
Connect-AzureAD
Add-PowerAppsAccount
$flows = Get-AdminFlow
$detailedFlows = @()
foreach ($flow in $flows) {
$ADUser = $null
try {
$ADUser = (Get-AzureADUser -ObjectId $flow.CreatedBy.userId)
}
catch {
Write-Warning "User not found for ObjectId: $($flow.CreatedBy.userId)"
}
if ($ADUser) {
$lastRun = (Get-FlowRun -EnvironmentName $flow.EnvironmentName -FlowName $flow.FlowName | Sort-Object -Property StartTime -Descending | Select-Object -First 1)
$detailedFlows += [PSCustomObject]@{
flowName = $flow.DisplayName
creatorID = $ADUser.UserPrincipalName.Substring(0, 6)
creatorName = $ADUser.DisplayName
creatorDept = $ADUser.Department
modifiedTime = $flow.LastModifiedTime
lastExecutionTime = $lastRun.StartTime
status = $lastRun.Status
enable = $flow.Enabled
}
}
}
$detailedFlows | Export-Csv -Path "../flow_detail.csv" -Encoding UTF8