Microsoft Entra Suite Tech Accelerator
Aug 14 2024, 07:00 AM - 09:30 AM (PDT)
Microsoft Tech Community

How to List of Azure AD groups for a Service Principal using Power shell

Brass Contributor



I want to fetch list of Azure AD groups which are assigned/ added as member for a service principal.


I am using below script but it is taking too much of time due to for loop each AD group check, Can you please suggest any other way we can do in optimized.


$ADGroups = Get-AzADGroup
foreach ($ADGroup in $ADGroups)
$GroupMembers = Get-AzADGroupMember -ObjectId $ADGroup.Id | where-Object {$_.Type -eq "ServicePrincipal"}

$GroupMember = $GroupMembers | where-Object {$_.DisplayName -eq "xxxxxxxxx"}
$string = [pscustomobject]@{
    "ServicePrincipalName" = $GroupMember.DisplayName
    "ADGroupName" = $ADGroup.DisplayName


1 Reply
1 best response