【问题标题】:Powershell : Get-AzureADGroupMember get all memebers of nested groupsPowershell : Get-AzureADGroupMember 获取嵌套组的所有成员
【发布时间】:2021-08-05 12:50:02
【问题描述】:
我有一个由其他 3 个组组成的 azure AD 组。
在 Azure 中预览组我可以看到两个选项卡,“直接”和“所有成员”。直接显示三个组,“所有成员”列出组和这些组的所有成员。
我正在尝试获取此组合组中所有成员的列表,但是当我使用
Get-AzureADGroupMember 它只给了我“直接”版本。
我可以调用什么方法?
【问题讨论】:
标签:
azure
powershell
azure-active-directory
【解决方案1】:
目前我已经制作了自己的函数来解决这个问题,它需要一个 objectId 作为参数(必须是一个组),然后递归地遍历列表。
Function Get-AzureADGroupMembers($groupId) {
$output = @()
$group = (Get-AzureADGroupMember -ObjectId $groupId -All $True| Select ObjectId).ObjectId
foreach($objectid in $group)
{
$aad_object = Get-AzureADObjectByObjectId -ObjectId $objectid
#Add to output if object is a user
if ($aad_object.ObjectType -eq 'User')
{
$output += New-Object PSObject -property @{
ObjectId = $aad_object.ObjectId
}
}
#Recursive call if the object is a group
if ($aad_object.ObjectType -eq 'Group')
{
$output += Get-AzureADGroupMembers -groupId $aad_object.ObjectId
}
}
return $output
}