Get-MgmtGraphGroupMemberOf
MgmtGraph: Retrieves groups/containers that this group is a member of
#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
'All' = $true
'ConsistencyLevel' = 'eventual'
'ErrorAction' = 'Stop'
}
$containers = $null
if ($ResultType) {
switch ($ResultType) {
'AsAdministrativeUnit' {
$containers = Get-MgGroupMemberOfAsAdministrativeUnit @params
}
'AsGroup' {
$containers = Get-MgGroupMemberOfAsGroup @params
}
}
}
else {
$containers = Get-MgGroupMemberOf @params
}
$results = foreach ($c in $containers) {
$displayName = $c.AdditionalProperties['displayName']
if ($null -eq $displayName) { $displayName = $c.DisplayName }
$description = $c.AdditionalProperties['description']
if ($null -eq $description) { $description = $c.Description }
$type = $ResultType
if (-not $type) { $type = $c.AdditionalProperties['@odata.type'] -replace '^#microsoft.graph.', '' }
[PSCustomObject]@{
GroupId = $GroupId
ParentId = $c.Id
DisplayName = $displayName
Description = $description
Type = $type
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. The type of parent container to retrieve. Supported values: AsAdministrativeUnit, AsGroup.