Skip to content

Get-MgmtGraphGroupMemberOfCount

MgmtGraph: Retrieves the count of parent containers for a group

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

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

    [ValidateSet('AsAdministrativeUnit', 'AsGroup')]
    [string]$ResultType
)

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

        $count = $null

        if ($ResultType) {
            switch ($ResultType) {
                'AsAdministrativeUnit' {
                    $count = Get-MgGroupMemberOfCountAsAdministrativeUnit @params
                }
                'AsGroup' {
                    $count = Get-MgGroupMemberOfCountAsGroup @params
                }
            }
        }
        else {
            $count = Get-MgGroupMemberOfCount @params
        }

        $result = [PSCustomObject]@{
            GroupId       = $GroupId
            TypeFilter    = if ($ResultType) { $ResultType } else { 'All' }
            MemberOfCount = $count
            Timestamp     = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
        }

        Write-Output $result
    }
    catch {
        throw
    }
}

The unique identifier of the child Microsoft Graph group.

Optional. The type of parent container to count. Supported values: AsAdministrativeUnit, AsGroup.

An interactive directory of PowerShell scripts.