Get-MgmtGraphGroupTransitiveMemberCount
MgmtGraph: Retrieves transitive group member counts
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Groups
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
[string]$GroupId,
[ValidateSet('AsApplication', 'AsDevice', 'AsGroup', 'AsOrgContact', 'AsServicePrincipal', 'AsUser')]
[string]$ResultType
)
Process {
try {
$params = @{
'GroupId' = $GroupId
'All' = $true
'ErrorAction' = 'Stop'
}
$count = $null
if ($ResultType) {
switch ($ResultType) {
'AsApplication' {
$count = Get-MgGroupTransitiveMemberCountAsApplication @params
}
'AsDevice' {
$count = Get-MgGroupTransitiveMemberCountAsDevice @params
}
'AsGroup' {
$count = Get-MgGroupTransitiveMemberCountAsGroup @params
}
'AsOrgContact' {
$count = Get-MgGroupTransitiveMemberCountAsOrgContact @params
}
'AsServicePrincipal' {
$count = Get-MgGroupTransitiveMemberCountAsServicePrincipal @params
}
'AsUser' {
$count = Get-MgGroupTransitiveMemberCountAsUser @params
}
}
}
else {
$count = Get-MgGroupTransitiveMemberCount @params
}
$result = [PSCustomObject]@{
GroupId = $GroupId
TypeFilter = if ($ResultType) { $ResultType } else { 'All' }
TransitiveMemberCount = $count
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
Write-Output $result
}
catch {
throw
}
}The unique identifier of the Microsoft Graph group.
Optional. The type of transitive members to count. Supported values: AsApplication, AsDevice, AsGroup, AsOrgContact, AsServicePrincipal, AsUser.