Skip to content

Instantly share code, notes, and snippets.

@ktskumar
Created June 5, 2021 06:10
Show Gist options
  • Save ktskumar/16ea9178d528dd58c9525f5c3a036e80 to your computer and use it in GitHub Desktop.
Save ktskumar/16ea9178d528dd58c9525f5c3a036e80 to your computer and use it in GitHub Desktop.
Export all flow run histories from the Default Environment in Power Platform
Write-Host '****** Export All Flow run histories into CSV ******'
#Provide Ouput Folder Path
$outputPath = "<Output Folder Path>"
$timestamp = Get-Date -Format "yyyymmddhhmmss"
$flowhistoryValues = @()
$environmentId = $(m365 flow environment list --query "[?contains(name,'Default')]" -o json | ConvertFrom-Json).Name
$flows = m365 flow list --environment $environmentId -o json | ConvertFrom-Json
Write-Host 'Fetching all flow run histories'
foreach ($singleflow in $flows) {
$flowruns = m365 flow run list --environment $environmentId --flow $singleflow.name -o json | ConvertFrom-Json
Write-Host $singleflow.displayName ' (' $flowruns.Count ')'
if ($flowruns.Count -gt 0) {
foreach ($singlerun in $flowruns) {
$flowhistoryObject = New-Object -TypeName PSObject
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Display Name' -Value $singleflow.displayName
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Name' -Value $singleflow.name
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Run ID' -Value $singlerun.name
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Start Time' -Value $singlerun.startTime
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Status' -Value $singlerun.status
$flowhistoryValues += $flowhistoryObject
}
}
else {
$flowhistoryObject = New-Object -TypeName PSObject
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Display Name' -Value $singleflow.displayName
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Name' -Value $singleflow.name
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Run ID' -Value ''
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Start Time' -Value ''
$flowhistoryObject | Add-Member -MemberType NoteProperty -Name 'Status' -Value ''
$flowhistoryValues += $flowhistoryObject
}
}
Write-Host 'Exporting all flow histroy in CSV format'
$filepath = $outputPath + 'flowrun_' + $timestamp + '.csv'
$flowhistoryValues | Export-Csv -Path $filepath -NoTypeInformation
Write-Output 'Complete.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment