Powershell Azure See 无法查看联系人所在的组

Powershell Azure See Cannot See what groups a contact is in

我正在尝试查看联系人所属的组。为了提供一些背景信息,联系人隐藏在我正在查看的 tenet 的目录中,因为它是用户实际上分开的姐妹 tenet 的别名。我正在使用 PS 并且 cmd 运行但没有显示任何结果。有人可以告诉我我可能哪里出错了吗?用户的电子邮件地址存储在名为 contact

的变量字符串中

代码:

Get-MsolGroup -All | Where-Object {$_.Members -contains $contact}

当我在 PowerShell 中输入此命令时,没有显示任何结果

未经测试,但我相信这应该有效。它应该 return ObjectIdDisplayName $contact 所属的组。

$groups = Get-MsolGroup -All
$contact = 'someUser@someCompany.com'

foreach($group in $groups)
{
    $members = Get-MsolGroupMember -GroupObjectId $group.ObjectId

    if($contact -in $members.EmailAddress)
    {
        $group | Select-Object ObjectId, DisplayName
    }
}