Grab a list of all groups and their member count on AzureAD with PowerShell

First thing will be to install and import the needed modules

Install-Module AzureAD
Import-Module AzureAD

Install-Module Az
Import-Module Az

From here we need to define what we will feed into our foreach loop with the following

$groups = Get-AzureADGroup

Note you can call $groups whatever you want, you will then feed this into our loop with the following

Install-Module AzureAD
Import-Module AzureAD

Install-Module Az
Import-Module Az

$groups = Get-AzureADGroup

foreach ($group in $groups){

Write-Output $group.Displayname (Get-AzureADGroupMember -ObjectId $group.objectid -all 1).count 
}

You can export an output similar to
“Group name
Count”

You can easily change this to your needs, export it with export-csv and so on.