PowerPlatform : PowerAutomate – PowerShell script to list all PowerAutomates / Flows in a tenant and export to CSV file

PowerShell script to get all PowerAutomates from the tenant
PowerShell script to get all PowerAutomates from the tenant

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂

Today one more PowerShell script along with Power Automate

Background : My management need all the list of Power Automates implemented in the tenant so this script born 🙂 Even though small script but sharing. SHARING IS CARING

Details / Steps :

  • We will use Get-AdminFlow CMDLET to return list of all flows in tenant
  • Permissions required :
    • Global Administrator
    • Environment Administrator
    • Power Platform Administrator
$powerAutomates = Get-AdminFlow

  • Once we have list of Power Automates from tenant, we will loop through each Power Automate and get the details as
# loop through each power automate
foreach ($powerAutomate in $powerAutomates)
{

    #Get the user from Created By field of Power Automate
    $user = Get-UsersOrGroupsFromGraph -ObjectId $powerAutomate.CreatedBy.userId

    #prepare the row to write the details in CSV file
    $row = @{
        ResourceType = 'PowerAutomate'
        DisplayName = $powerAutomate.displayName
        EnvironmentName = $powerAutomate.environmentName
        CreatedByEmail = $user.DisplayName
    }

    $powerAutomateListings+= $(new-object psobject -Property $row)
}

  • Lets see the PowerAutomate object details – which properties are exposed.
Fig : Power Platform – Power Automate – PowerShell script for fetching all Power Automates from the Tenant
  • Here we are using Get-UsersOrGroupsFromGraph CMDLET to get the user object. So that we can have user display name
Fig : Power Platform – Power Automate – PowerShell script for fetching all Power Automates from the Tenant – Getting user details from Power Automate created by field
  • Final step is write to CSV file using Export-Csv CMDLET

# output to file on given Path
$powerAutomateListings | Export-Csv -Path $Path

Complete PowerShell script:

<#  
    Outputs a .csv file of records that represent list of PowerAutomates from the tenant it is run in. Result feature records will include:
        - PowerAutomate display name
        - Environment Name
        - User display name who created the Power Automate
#>

param(
    [string]$Path = 'c:\List_PowerAutomate_Details.csv'
)
    
    #Get all PowerAutomates the Tenant - with proper respective permissions
        # Global Administrator
        # Environment Administrator
        # Power Platform Administrator

    $powerAutomates = Get-AdminFlow 

    $powerAutomateListings = @()

# loop through each power automate
foreach ($powerAutomate in $powerAutomates)
{

    #Get the user from Created By field of Power Automate
    $user = Get-UsersOrGroupsFromGraph -ObjectId $powerAutomate.CreatedBy.userId

    #prepare the row to write the details in CSV file
    $row = @{
        ResourceType = 'PowerAutomate'
        DisplayName = $powerAutomate.displayName
        EnvironmentName = $powerAutomate.environmentName
        CreatedByEmail = $user.DisplayName
    }
    $powerAutomateListings+= $(new-object psobject -Property $row)
}

# output to file on given Path
$powerAutomateListings | Export-Csv -Path $Path

Knowledge Junction has various PowerShell cmdlet in its Kitty, please have a look – https://knowledge-junction.in/category/technology-articles/powershell-cmdlets/

Thanks for reading 🙂 If its worth at least reading once, kindly please like and share 🙂 SHARE ING IS CARING 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.