PowerPlatform : PowerApps – PowerShell script to list all PowerApps and respective connections used from the M365 tenant

PowerShell script to fetch all PowerApps and respective connection details in M365 tenant
PowerShell script to fetch all PowerApps and respective connection details in M365 tenant

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂

Today something different related to Power Apps.

Background: My management has asked to list all PowerApps / PowerAutomates where SharePoint connection is used in our M365 tenant. This is something new for me so reasearch and then found an option of PowerShell script for listing PowerApps and respective connection details. But for PowerAutomate there is bit different approach which we will discuss in next article

Details / Steps:

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

PowerShell - PowerPlatform - Installing PowerApps Admin PowerShell Module
Fig : PowerShell – PowerPlatform – Installing PowerApps Admin PowerShell Module
PowerShell - PowerPlatform - Installing PowerApps Admin PowerShell Module
Fig : PowerShell – PowerPlatform – Installing PowerApps Admin PowerShell Module
 $powerApp = Get-AdminPowerApp 

Fig : Output of Get-AdminPowerApp cmdlet – Returns list of all PowerApps which current user has access
  • We will loop through each and every app
  • We will use connectionReferences property of app – Internal.properties.connectionReferences – This property returns list of all connections used for app
$powerApp.Internal.properties.connectionReferences

Fig : Output of – $powerApp.Internal.properties.connectionReferences – returns list of connection references of App
  • We will loop through each connection for app returned by connectionReferences property we will get the connection object
  • From connection object we will fetch the connection id using Get-Member CMDLET as
$connectionId in ($connection | Get-Member -MemberType NoteProperty).Name

Fig : PowerApp connection detailes fetched
  • Once we have connection id for every connection reference of App we will get the connection details
  • We will prepare a row for every connection to add in CSV file
  • We will export the CSV file using Export-Csv CMDLET
# output to file
$powerAppListings | Export-Csv -Path $Path

Complete PowerShell script:

<#  
    Preparing a .csv file having list of PowerApps and respective connections used from the tenant
#>

param(
    [string]$Path = 'c:\powerApps_ConnectionDetails.csv'
)

#fetch the list of all PowerApps from the tenant. 
#when the below CMDLET will execute it will ask for credentials for the tenant
$powerApps = Get-AdminPowerApp 

$powerAppListings = @()

# loop through each app
foreach ($powerApp in $powerApps)
{
    # loop through each connection reference for the respective APP
    foreach($connectionReference in $powerApp.Internal.properties.connectionReferences)
    {
        #loop through each connection from the connection reference
        foreach($connection in $connectionReference)
        {
            foreach ($connectionId in ($connection | Get-Member -MemberType NoteProperty).Name) 
            {
                #get the connection details
                $connectionDetails = $($connection.$connectionId)

                    #preparing row
                    $csvRow = @{
                        AppDisplayName = $powerApp.displayName
                        AppName = $powerApp.appName
                        EnvironmentName = $powerApp.environmentName
                        ConnectorDisplayName = $connectionDetails.displayName
                        ConnectionId = $connectionDetails.id
                        ConnectionName = $connectionDetails.connectionName
                        CreatedByEmail = $powerApp.owner.email
                        IsPremiumConnector = $connectionDetails.apiTier -eq 'Premium'
                    }
                    $powerAppListings+= $(new-object psobject -Property $csvRow)
            }
        }        
    }
}

# output to file
$powerAppListings | Export-Csv -Path $Path

  • Output of the CSV file will lokk like as
Fig : CSV file having list of all PowerApps in tenant with respective connection details

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

Knowledge Junction has good series of articles on Power Platform, please have a look once for more details – https://knowledge-junction.in/?s=power+platform

Reference:

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 Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

5 Responses

  1. hanqing123234 says:

    Hi, thanks for you sharing! it is really useful to me! May I ask how can I list all users of the connectors?

  2. itmatt123 says:

    Hi Prasham,
    This is an extremely helpful script! Thank you for sharing it!
    Can you tell me how I can get the CSV file headers in a particular order? If you look at the Array variable $csvRow the order of the members of the array do not match the order of the CSV file.
    For Example:
    – your array has “AppDisplayName”, “AppName” then EnvironmentName…
    – You CSV report headers are in a different order and start with “AppDisplayName”, “IsPremiumConnector” then “ConnectionId”.. which is a different order the how they were added to the array.

    Why is it in a different order? Is it possible to get the column headers is specific order?

  1. August 27, 2021

    […] PowerPlatform : PowerApps – PowerShell script to list all PowerApps and respective connections use… […]

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

%d bloggers like this: