How to get the Group Types for the groups present in Entra ID like Microsoft 365, Security using Powershell script

MURALIDHAR 0 Reputation points
2025-10-23T12:50:30.9866667+00:00

I am getting the below result when checking for a Security group using Mggraph command. User's image

Is there any script with which we can download all the groups in the tenant in the EntraID with the group type defined respectively for all types of groups like Mail enabled security, Microsoft 365, Distribution, Security etc... Appreciate if someone can share any script on this

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rukmini 2,850 Reputation points Microsoft External Staff Moderator
    2025-10-23T13:01:45.1433333+00:00

    Hello MURALIDHAR,

    To get the Group Types for the groups present in Entra ID like Microsoft 365, Security using Powershell script make use of below PowerShell script:

    
    $groupId = "GroupID"
    
    $g = Get-MgGroup -GroupId $groupId
    
    if ($g.GroupTypes -contains "Unified") {
    
        $type = "Microsoft 365"
    
    }
    
    elseif ($g.MailEnabled -eq $true -and $g.SecurityEnabled -eq $true) {
    
        $type = "Mail-enabled Security"
    
    }
    
    elseif ($g.MailEnabled -eq $true -and $g.SecurityEnabled -eq $false) {
    
        $type = "Distribution"
    
    }
    
    else {
    
        $type = "Security"
    
    }
    
    $g | Select DisplayName, Mail, MailEnabled, SecurityEnabled, GroupTypes, @{Name="GroupType";Expression={$type}}
    
    

    User's image

    To iterate through all groups, use below script:

    
    Connect-MgGraph -Scopes "Group.Read.All"
    
    $groups = Get-MgGroup -All
    
    $results = foreach ($g in $groups) {
    
        if ($g.GroupTypes -contains "Unified") {
    
            $type = "Microsoft 365"
    
        }
    
        elseif ($g.MailEnabled -eq $true -and $g.SecurityEnabled -eq $true) {
    
            $type = "Mail-enabled Security"
    
        }
    
        elseif ($g.MailEnabled -eq $true -and $g.SecurityEnabled -eq $false) {
    
            $type = "Distribution"
    
        }
    
        else {
    
            $type = "Security"
    
        }
    
        [PSCustomObject]@{
    
            DisplayName      = $g.DisplayName
    
            Mail             = $g.Mail
    
            MailEnabled      = $g.MailEnabled
    
            SecurityEnabled  = $g.SecurityEnabled
    
            GroupTypes       = if ($g.GroupTypes) { $g.GroupTypes -join "," } else { "" }
    
            GroupType        = $type
    
            Id               = $g.Id
    
        }
    
    }
    
    $results | Sort-Object DisplayName | Format-Table -AutoSize
    
    

    Hope this helps!

    If this answers your query, do click Accept Answer and Yes, if you have any further queries do let us know.

    User's image

    If you have any other questions, let me know in the “comments” and I would be happy to help you.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.