Azure AD 组和组成员避免将其他组作为成员

问题描述 投票:0回答:1

我正在尝试汇总特定 Azure AD 组内所有成员的报告,一切正常,直到其中一个成员是另一个 AD 组而不是常规用户名。在下图中,第 3 行的 Username 和 UserPrincipalName 为空,因为 UserId 实际上是组 ID

enter image description here

下面是我在 Azure runbook POwershell 7.2 中运行的 powershell

$结果数组=@()

$groups = get-mggroup -全部 | Where-Object {$.DisplayName -eq 'MT' - 或 $.DisplayName - 如 'MT_ *'}

ForEach ($group in $groups) { $members = Get-MgGroupMember -GroupId $group.Id ForEach($members 中的 $member){

$用户名 = (get-mguser -UserId $member.Id).DisplayName $principalusername = (get-mguser -UserId $member.Id).UserPrincipalName

$UserObject = 新对象 PSObject $UserObject |添加成员 -membertype NoteProperty -名称“GroupId” -Value $group.Id $UserObject | add-member -membertype NoteProperty -name "GroupName" -Value $group.DisplayName $UserObject | $group.DisplayName添加成员-membertype NoteProperty -名称“UserId”-Value $member.Id $UserObject | add-member -membertype NoteProperty -name "UserName" -Value $用户名 $UserObject | add-member -membertype NoteProperty -name "UserPrincipalName" -Value $principalusername $resultsarray += $UserObject

}

}

$结果数组 |导出 CSV - 编码 ASCII ($env:TEMP2+"ADGroupsANDUsers.csv") -Notype

$Context = New-AzStorageContext -StorageAccountName 'teststorage01'

Set-AzStorageBlobContent -Context $Context -Container“test”-File ($env:TEMP2+"ADGroupsANDUsers.csv") -Blob "ADGroupsANDUsers.csv" -力量

这只是一个想法,如何让用户成为另一个 AD 组的成员,但你们可能有更好的解决方案,我只需要一些有关此类场景的理想解决方案的指导。我希望我可以告诉大家不要将一个 AD 组添加为另一个 AD 组的成员:(

enter image description here

我正在寻找理想的 powershell 代码来处理这种情况

powershell azure-runbook
1个回答
0
投票

根据 Santiago Squarzon 评论,我替换了代码

$members = Get-MgGroupMember -GroupId $group.Id

$members = Get-MgGroupTransitiveMember -GroupId $group.Id

现在我可以看到 AD 组后面所有嵌套的真实用户名,它是主 AD 组的一部分,依此类推。

© www.soinside.com 2019 - 2024. All rights reserved.