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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s