我在从AzureAD获取一系列组的所有成员时遇到问题。谁可以帮助我?提前感谢您使用下面的脚本,我可以检索1个组的成员,并且工作正常。
Connect-MgGraph
$GROUP_NAME = 'SUG-APP-MAN-SPBI_BICC-P'
$group = Get-MgGroup -Filter "DisplayName eq '$GROUP_NAME'"
$members = Get-MgGroupMember -GroupId $group.Id
$users = @()
foreach ($member in $members)
{
$user = Get-MgUser -UserId $member.Id
$users += New-Object PSObject -Property @{Group = $group.DsplayName;
Name = $user.DisplayName;
USERPRINCIPALNAME = $user.Mail}
}
$users | Format-Table
我试图检索一个组范围内的所有成员。问题是我如何定义变量$GROUP_NAME
Connect-MgGraph
$GROUP_LIST = Get-MgGroup
foreach ($Group in $GROUP_LIST)
{
$GROUP_NAME = $GROUP_LIST
$group = Get-MgGroup -Filter "DisplayName eq '$GROUP_NAME'"
$members = Get-MgGroupMember -GroupId $group.Id
$users = @()
foreach ($member in $members)
{
$user = Get-MgUser -UserId $member.Id
$users += New-Object PSObject -Property @{Group = $group.DsplayName;
Name = $user.DisplayName;
USERPRINCIPALNAME = $user.Mail}
}
}
$users | Format-Table
错误:
1条答案
按热度按时间zi8p0yeb1#
这对我很有效