Skip to content

Get-MgmtGraphGroupMemberGroup

MgmtGraph: Retrieves groups that a specifies group is a member of

#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Groups

[CmdletBinding()]
Param (
    [Parameter(Mandatory = $true, Position = 0)]
    [string]$GroupId,

    [bool]$SecurityEnabledOnly = $false
)

Process {
    try {
        $params = @{
            'GroupId'             = $GroupId
            'SecurityEnabledOnly' = $SecurityEnabledOnly
            'ErrorAction'         = 'Stop'
        }

        $groupIds = Get-MgGroupMemberGroup @params
        
        $results = foreach ($id in $groupIds) {
            [PSCustomObject]@{
                SourceGroupId = $GroupId
                MemberOfGroupId = $id
                Timestamp     = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

        Write-Output $results
    }
    catch {
        throw
    }
}

The unique identifier of the child Microsoft Graph group.

Optional. If set to $true, returns only security-enabled groups. If $false, returns all groups.

An interactive directory of PowerShell scripts.