I'm working on a script to collect Azure Group IDs assigned to Azure SAAS Applications or Conditional Access Policies. Currently, I'm exporting a list of user details (just email addresses for testing). The script successfully retrieves Group ID details from the application or CA policy. However, when I try to gather members assigned to these groups, including users from nested groups, the count of users returned is only about a quarter of what Entra indicates should be in the groups. I'm not sure if there's a logic error in my function or if some part of the data is being overwritten, preventing the return of all users.
1 Answer
It looks like you might need to consider using a `switch` statement for better handling of your group members. Instead of using `+= $SubUsers`, which can slow things down, try something like this:
```powershell
Function GetAzureADMembers {
Param([Parameter(Mandatory = $True)]$AzureGroupID)
$GroupInfo = Get-MgGroup -GroupId $AzureGroupID
$SubGroupMembers = Get-MgGroupMember -GroupId $AzureGroupID
foreach ($SingleMember in $SubGroupMembers) {
switch ($SingleMember) {
{ $_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.user' } { [PSCustomObject]@{ Name = $_.AdditionalProperties.displayName; Mail = $_.AdditionalProperties.mail } }
{ $_.AdditionalProperties.'@odata.type' -eq '#microsoft.graph.group' } { GetAzureADMembers -AzureGroupID $SingleMember.id }
Default { [PSCustomObject]@{ Name = $_.Id; Mail = 'UNKNOWN' } }
}
}
}
```
This approach is more efficient and might help with your returning users. I tested it and it should work similarly with your Entra functions—just remember the correct object paths!
Related Questions
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String