Getting List Of Users Accessing PowerApp

Introduction

In this article, we will go through the steps to get the users who have access to the Power App. MSFT has released the Powershell support for PowerApps. The Powershell modules for PowerApps need to be installed first. The installation steps are mentioned in the references section.

Prerequisites

  • You need to be the owner of the app to run the script.
  • It is required to have Powershell version greater than 5

Steps

Step 1

Get the App ID to the PowerApp where you need to get the users who have access to your app. The app ID can be found at ‘Details’ tab in the Powerapps maker portal. (https://make.powerapps.com)

$AppId = "ce5a56f3-4b70-4479-a401-a087b071e03b"

Step 2

Connect to PowerApps account. This will be your UPN where it has owner access to your Power App. When running the below command it will ask you to authenticate and enter your organizational credentials.

Add-PowerAppsAccount

Step 3

There is a command ‘Get-PowerAppRoleAssignment’ which will get all the users and their permission levels. Get the output and store in a variable and finally export to CSV. The below one line command does that job for you.

When running the Get-PowerAppsRoleAssignment with $AppID, it will give all the values. Below is the output that it returns.

$AppUsers = Get-PowerAppRoleAssignment -AppName $AppId

It gets RoleId, RoleName, PrincipalDisplayName, PrincipalEmail, PrincipalObjectId, PrincipalType, RoleType, AppName, EnvironmentName, Internal.

Step 4

Here I am interested in getting the Email, Role Type, and Display Name. I am modifying the above command to below and my output is much cleaner. You can also modify the below query by modifying your select query.

$AppUsers = Get-PowerAppRoleAssignment -AppName $AppId | Select PrincipalEmail, RoleType, PrincipalDisplayName

Step 5

Finally, I would like to get the export of the above results in CSV file. For this, I am extending the command with pipe and appending ‘Export-csv’.

$AppUsers = Get-PowerAppRoleAssignment -AppName $AppId | Select PrincipalEmail, RoleType, PrincipalDisplayName | Export-Csv -Path "C:\Output\$OutputFile"

Make sure to substitute the variables -path according to your needs.

Complete Script

#Initializing current time
$CurrentTime = $(Get-Date).ToString("yyyymmddhhmmss")  
#intializing the output file name with datetime so that each time it is unique value when run
$OutputFile="C:\Output\AppUsersInfo-"+$currentTime+".csv" 
Add-Content -Path $outputFile -Value "Email, Role Type"
$AppId = "ce5a56f3-4b70-4479-a401-a087b071e03b"
Add-PowerAppsAccount
$AppUsers = Get-PowerAppRoleAssignment -AppName $AppId | Select PrincipalEmail, RoleType, PrincipalDisplayName | Export-Csv -Path $OutputFile

Output

References

  1. https://docs.microsoft.com/en-us/power-platform/admin/powerapps-powershell
  2. https://www.c-sharpcorner.com/article/getting-dlp-policy-details-in-power-platform-environment 


Similar Articles