Showing results for 
Search instead for 
Did you mean: 
Post Patron
Post Patron

Retrieve a power automate flow with powershell

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", 
    "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": "",
            "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 {
        [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 = $











Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,600)