Created
June 5, 2021 06:10
-
-
Save ktskumar/16ea9178d528dd58c9525f5c3a036e80 to your computer and use it in GitHub Desktop.
Export all flow run histories from the Default Environment in Power Platform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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