我正在尝试列出组中包含特定 SMTP 地址的所有组。下面是我正在使用的代码,但它输出所有内容,而不仅仅是具有指定 SMTP 地址的组:
$temp = Get-DistributionGroup -ResultSize Unlimited
foreach ($group in $temp)
{
if (Get-DistributionGroupMember $group | select -ExpandProperty PrimarySmtpAddress`
| ForEach-Object {$_.PrimarySmtpAddress -match "contoso.com"}) {
Write-Output "GroupName:$group "
Write-Output "GroupName:$($group.PrimarySmtpAddress) "
Write-Output "GroupMembers:"
Get-DistributionGroupMember $group|ft displayname,primarysmtpaddress
}
else
{
Write-Host "null"
}
}