我在Azure Active Directory中有一个组,它具有嵌套组。我想出口的用户列表,连同他们的B组运行powershell脚本.理想情况下,我想输出显示用户的姓名,电子邮件和组。我试着写一个脚本,但我只能列出组或只有名字,但不是所有的东西在一起。
目前我有下面的代码,但我不知道为什么我一直得到错误:Get-AzureADGroupMember:无法将参数绑定到参数“ObjectId”,因为它为Null。
$groups=Get-AzureADGroup -SearchString 'my-group-name'
$resultsarray =@()
ForEach ($group in $groups)
{
$members = Get-AzureADGroupMember -ObjectId $group.ObjectId
#Recursive call if the object is a group
if ($members.ObjectType -eq 'Group')
{
$resultarray += Get-AzureADGroupMembers -ObjectId $member.ObjectId
}
}
#Add to output if object is a user
if ($members.ObjectType -eq 'User')
{
ForEach ($member in $members){
$UserObject = new-object PSObject
$UserObject | add-member -membertype NoteProperty -name "Group Name" -Value $group.DisplayName
$UserObject | add-member -membertype NoteProperty -name "Member Name" -Value $member.DisplayName
$UserObject | add-member -membertype NoteProperty -name "ObjType" -Value $member.ObjectType
$UserObject | add-member -membertype NoteProperty -name "UserType" -Value $member.UserType
$UserObject | add-member -membertype NoteProperty -name "UserPrinicpalName" -Value $member.UserPrincipalName
$resultsarray += $UserObject
}
}
$resultsarray | Export-Csv -Encoding UTF8 -Delimiter ";" -Path 'C:\Users\Desktop\aadgroupmembers.csv'
1条答案
按热度按时间thtygnil1#
我创建了一个Azure AD组并添加了成员,如下所示:
并在嵌套组**
rukgroup
**中添加如下成员:要获取用户列表和嵌套组,请使用以下PowerShell脚本:
CSV文件成功导出,嵌套组名成员如下: