Export Power Automate run using PowerShell Script

Power Automate flow stores 28 days for history for each flows in an environment. This is a quite a comprehensive log to troubleshoot any error during the executions of the flow. Though there are contextual data that you can add to the history view, exporting and viewing at the historical runs is quite not easy. Let say if you want to view a run that is more than a week then it is not that easy enough to filter or search the run yet.

There isn’t a easy way to extract the previous run history over that 28 days. There is a export to csv option available which only extract the last 100 runs only. If you want to extract the whole run then you can use PowerShell script to extract the while dumb. This will be very handy in the case of investigating any past runs.

In order to extract using PowerShell firstly, PowerApps modules needs to imported. Run PowerShell as an administrator, if you are not a local admin then you can use the -Scope CurrentUser parameter for installation.

Run the below script if you are non-admin

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell -Scope CurrentUser
Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber -Scope CurrentUser

Run the below script if you are a local admin user

Install-Module -Name Microsoft.PowerApps.Administration.PowerShell
Install-Module -Name Microsoft.PowerApps.PowerShell -AllowClobber

Follow the prompts and finish the installation. Now that you have successfully installed the necessary PowerApps modules, let get in to the commands to extract the logs.

Copy and paste the below code in the PowerShell ISE. Click run, It will prompt you to login to your organisation first. Once successfully logged in it will present with series of prompt to select your environment and flow once selected the csv log will be exported in the root directory.

$environmentArray = (Get-AdminPowerAppEnvironment | Select -Property EnvironmentName, DisplayName)
$num = 1
foreach ($environment in $environmentArray){
  $tempString = "{0} - {1} ({2})" -f 
  Write-Host $tempString
$promptString = "Enter option between 1 - {0}" -f ($num -1)
$option = Read-Host $promptString
$envSelected = $option - 1
$flowArray = (Get-AdminFlow -EnvironmentName $environmentArray[$option - 1].EnvironmentName | Select -Property FlowName,DisplayName)
$num = 1
foreach ($flow in $flowArray){
  $tempString = "{0} - {1} ({2})" -f 
  Write-Host $tempString
$promptString = "Enter option between 1 - {0}" -f ($num -1)
$option = Read-Host $promptString
$flowSelected = $option - 1
Get-FlowRun -EnvironmentName $environmentArray[$envSelected].EnvironmentName -FlowName $flowArray[$flowselected].FlowName | Export-Csv -Path '.\FlowRunExport.csv'

Sample data will look something like below.

  • Flow run Name – 08585352233746820151016101172CU14
  • Status – Succeeded
  • StartTime – 2022-09-21T00:33:34.8156295Z
  • Internal – @{name=08585352233746820151016101172CU14 ; id=/providers/Microsoft.ProcessSimple/environments/2af70500-14f5-3382-9b0c-786c6ab931af/flows/0023ed0e-5545-9761-d1ba-3d74445545ba2/runs/08585352233746820151016101172CU14 ; type=Microsoft.ProcessSimple/environments/flows/runs; properties=}

The flow run URL will look something, replace those relevant value and you will get the run history.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s