Skip to content

Get-MgmtGraphGroupTransitiveMemberOfCount

MgmtGraph: Retrieves transitive parent count 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-MgGroupTransitiveMemberOfCountAsAdministrativeUnit @params
                }
                'AsGroup' {
                    $count = Get-MgGroupTransitiveMemberOfCountAsGroup @params
                }
            }
        }
        else {
            $count = Get-MgGroupTransitiveMemberOfCount @params
        }

        $result = [PSCustomObject]@{
            GroupId                 = $GroupId
            TypeFilter              = if ($ResultType) { $ResultType } else { 'All' }
            TransitiveMemberOfCount = $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.