Display users and groups assigned to an Application Proxy application
This PowerShell script example lists the users and groups assigned to a specific Microsoft Entra application proxy application.
If you don't have an Azure subscription, create an Azure free account before you begin.
Note
We recommend that you use the Azure Az PowerShell module to interact with Azure. See Install Azure PowerShell to get started. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.
Azure Cloud Shell
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.
To start Azure Cloud Shell:
Option | Example/Link |
---|---|
Select Try It in the upper-right corner of a code or command block. Selecting Try It doesn't automatically copy the code or command to Cloud Shell. | ![]() |
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser. | ![]() |
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal. | ![]() |
To use Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block (or command block) to copy the code or command.
Paste the code or command into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.
Select Enter to run the code or command.
This sample requires the Azure Active Directory PowerShell 2.0 for Graph module or the Azure Active Directory PowerShell 2.0 for Graph module preview version (AzureADPreview).
Sample script
# This sample script displays users and groups assigned to the specified Application Proxy application.
#
# .\display-users-group-of-an-app.ps1 -ObjectId <ObjectId of the application>
#
# This script requires PowerShell 5.1 (x64) and one of the following modules:
# AzureAD 2.0.2.52
# AzureADPreview 2.0.2.53
#
# Before you begin:
# Run Connect-AzureAD to connect to the tenant domain.
# Required Azure AD role: Global Administrator or Application Administrator
param(
[string] $ObjectId = "null"
)
$aadapServPrincObjId=$ObjectId
If ($aadapServPrincObjId -eq "null") {
Write-Host "Parameter is missing." -BackgroundColor "Black" -ForegroundColor "Green"
Write-Host " "
Write-Host ".\display-users-group-of-an-app.ps1 -ObjectId <ObjectId of the application>" -BackgroundColor "Black" -ForegroundColor "Green"
Write-Host " "
Exit
}
Write-Host "Reading users. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
$users=Get-AzureADUser -Top 1000000
Write-Host "Reading groups. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
$groups = Get-AzureADGroup -Top 1000000
$aadapApp = $aadapServPrinc | ForEach-Object { $allApps -match $_.AppId }
Write-Host "Displaying users and groups assigned to the specified Application Proxy application..." -BackgroundColor "Black" -ForegroundColor "Green"
Write-Host " "
try { $app = Get-AzureADServicePrincipal -ObjectId $aadapServPrincObjId}
catch {
Write-Host "Possibly the ObjetId is incorrect." -BackgroundColor "Black" -ForegroundColor "Red"
Write-Host " "
Exit
}
Write-Host ("Application: " + $app.DisplayName + "(ServicePrinc. ObjID:" + $aadapServPrincObjId + ")")
Write-Host ("")
Write-Host ("Assigned (directly and through group membership) users:")
Write-Host ("")
$number=0
foreach ($item in $users) {
$listOfAssignments = Get-AzureADUserAppRoleAssignment -ObjectId $item.ObjectId
$assigned = $false
foreach ($item2 in $listOfAssignments) { If ($item2.ResourceID -eq $aadapServPrincObjId) { $assigned = $true } }
If ($assigned -eq $true) {
Write-Host ("DisplayName: " + $item.DisplayName + " UPN: " + $item.UserPrincipalName + " ObjectID: " + $item.ObjectID)
$number = $number + 1
}
}
Write-Host ("")
Write-Host ("Number of (directly and through group membership) users: " + $number)
Write-Host ("")
Write-Host ("")
Write-Host ("Assigned groups:")
Write-Host ("")
$number=0
foreach ($item in $groups) {
$listOfAssignments = Get-AzureADGroupAppRoleAssignment -ObjectId $item.ObjectId
$assigned = $false
foreach ($item2 in $listOfAssignments) { If ($item2.ResourceID -eq $aadapServPrincObjId) { $assigned = $true } }
If ($assigned -eq $true) {
Write-Host ("DisplayName: " + $item.DisplayName + " ObjectID: " + $item.ObjectID)
$number=$number+1
}
}
Write-Host ("")
Write-Host ("Number of assigned groups: " + $number)
Write-Host ("")
Write-Host ("")
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
Write-Host ("")
Script explanation
Command | Notes |
---|---|
Get-AzureADUser | Gets a user. |
Get-AzureADGroup | Gets a group. |
Get-AzureADServicePrincipal | Gets a service principal. |
Get-AzureADUserAppRoleAssignment | Get a user application role assignment. |
Get-AzureADGroupAppRoleAssignment | Get a group application role assignment. |
Next steps
For more information on the Azure AD PowerShell module, see Azure AD PowerShell module overview.
For other PowerShell examples for Application Proxy, see Azure AD PowerShell examples for Microsoft Entra application proxy.
Feedback
Submit and view feedback for