Aug 26 2020 10:38 PM
Hi,
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"}
if($GroupMember)
{
$string = [pscustomobject]@{
"ServicePrincipalName" = $GroupMember.DisplayName
"ADGroupName" = $ADGroup.DisplayName
}
$string
}
}
Aug 27 2020 02:04 AM
SolutionGot solution by using below script.
$ServicePrincipalId = Get-AzureADServicePrincipal -All $true | Where {$_.DisplayName -eq 'xxxxx'}
Get-AzureADServicePrincipalMembership -ObjectId $ServicePrincipalId.ObjectId
Aug 27 2020 02:04 AM
SolutionGot solution by using below script.
$ServicePrincipalId = Get-AzureADServicePrincipal -All $true | Where {$_.DisplayName -eq 'xxxxx'}
Get-AzureADServicePrincipalMembership -ObjectId $ServicePrincipalId.ObjectId