Get All groups from Azure Active Directory

How to get all group from Azure Active Directory using PowerShell module AzureAD AzureAD and count members.

$moduleName  = "AzureAD"
if (Get-Module -ListAvailable -Name $moduleName) {
    Write-Output "Module $moduleName all ready exists"
}
else
{
    Write-Output "Module $moduleName does not exist"

    try {
        Write-Output "Installing Module $moduleName"
        Install-Module -Name $moduleName -AllowClobber
    }
    catch [Exception] {
        $_.message
        exit
    }
}
Import-Module -Name $moduleName

#login
Connect-AzureAD

$AllGroups =Get-AzureADGroup -All $true
$AllGroups|measure

#apply filter by name
$ado=$AllGroups|where DisplayName -Like "GROUPNAME*"

foreach($g in $ado)
{
  $a=$g|Get-AzureADGroupMember |measure|select Count
  Write-Output  "$($g.DisplayName),$($a.Count)"
}

Share this on...

Rate this Post:

Share:

Topics:

General