Skip to main content
Community site session details

Community site session details

Session Id : D5LlUqpc7fZYgLaCPfVkd2
Power Automate - Using Flows
Answered

Retrieve a power automate flow with powershell

Like (0) ShareShare
ReportReport
Posted on 16 May 2022 15:36:59 by 691

Hello, I would like to make a PowerShell script where I use the "GetFlow" function to retrieve a Power Automate flow. But unfortunately when I run my powershell script nothing happens. Could you help me please ? 😞

Thanks in advance !

 

Here is my config file:

 

 

 

{
 "tenantId" : "0000000-0000-0000-0000-00000000", 
 "certifThumb" : "QHFHGELGEJGQJFOQQJEQJGJQLKGJQEGJEKL",
 "appId" : "0000000-0000-0000-0000-00000000",
 "triggerHour" : "01:00",
 "outputFile" : ".\\flow-stats.txt",
 "errorsFile" : ".\\flow-errors.txt",
 "dataFile" : ".\\flow-data.json",
 "flows" : [
 {
 "name": "Flux",
 "mailbox": "aaaaaa@aaaa.onmicrosoft.com",
 "serviceAccount" : "PS_FLOW"
 }
 ]
}

 

 

(Obviously I changed the confidential values to send the script here)

 

Here is my powershell script:

 

 

$ErrorActionPreference = "Stop"

$PSModulesNames = "Microsoft.PowerApps.PowerShell", "Microsoft.PowerApps.Administration.PowerShell"
$configFileName = "Flow-Stats.config"
$jsonDateFormat = "o" #2022-03-23T16:37:51.8011737+01:00

$PSModulesNames | ForEach-Object {
 Import-Module $_ -EA SilentlyContinue
 $module = Get-Module -Name $_
 if($null -eq $module) {
 throw "Module '$_' not found"
 }
}

$config = Get-Content ".\$configFileName" -Encoding UTF8 -EA SilentlyContinue | ConvertFrom-Json -EA SilentlyContinue
if($null -eq $config) {
 throw "Error reading config file '$configFileName'"
}

#Add-PowerAppsAccount -TenantID $config.tenantId -CertificateThumbprint $config.certifThumb -ApplicationId $config.appId

$data = Get-Content ".\$($config.dataFile)" -Encoding UTF8 -EA SilentlyContinue | ConvertFrom-Json -EA SilentlyContinue
if($null -eq $data) {
 $data = [PSCustomObject]@{
 lastExec = [datetime]::MinValue.ToString($jsonDateFormat)
 }
}
$lastExec = Get-Date $data.lastExec
$now = Get-Date
$flowIds = @{}

function GetFlowRuns {
 param(
 [string] $FlowName,
 [datetime] $Start,
 [datetime] $End
 )
 $runs = @(Get-FlowRun -FlowName $FlowName | Where-Object {
 $date = Get-Date $_.StartTime
 return $date -ge $Start -and $date -lt $End
 })
 $runCount = $runs.Count
 $errors = @($runs | Where-Object { $_.Status -eq "Failed" })
 $errorsCount = $errors.Count
 return [PSCustomObject]@{
 runCount = $runCount
 errorCount = $errorsCount
 errors = $errors | ForEach-Object {
 return [PSCustomObject]@{
 date = (Get-Date $_.StartTime).ToString($jsonDateFormat)
 message = $_.Internal.properties.error.message
 }
 }
 }
}

 

 

 

 

 

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    on 19 May 2022 at 05:27:22
    Re: Retrieve a power automate flow with powershell

    HI @s44,

    Sorry that I could not help you figure it out in this Power Automate forum, I suggest you go to Power Shell forum:

    https://forums.powershell.org/

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 2

Featured topics

Restore a deleted flow
Loading complete