电源外壳 |网上交流 |在启用审核的情况下查找高于 x 个成员的通讯组列表

PowerShell | Exchange Online | Find distribution lists above x members with enabled moderation

我正在尝试导出包含 x 个成员以上的通讯组列表(来自 Exchange Online)并启用审核的 csv。

这里的问题是它显示了所有具有我要求的属性的 DL,但完全忽略了“超过 100”的部分,并且没有显示每个 DL 的总数。

我使用的代码是:

$distgroups = Get-DistributionGroup -ResultSize Unlimited

foreach ($dg in $distgroups)
{

    $Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited

    if ($Members.count -ge 100)
        {
            Get-DistributionGroup -ResultSize Unlimited | select DisplayName,ModerationEnabled,AcceptMessagesOnlyFromSendersOrMembers
            (Get-DistributionGroupMember $dg.DisplayName).Count
        }
}
Export-Csv C:\Temp\DLs.csv -UseCulture

为了清楚起见,我以前用过这个但结果相同:

$distgroups = Get-DistributionGroup -ResultSize Unlimited

foreach ($dg in $distgroups)
{
    if ((Get-DistributionGroupMember $dg.DistinguishedName).Count -ge 100)
        {
            Get-DistributionGroup -ResultSize Unlimited | select DisplayName,ModerationEnabled,AcceptMessagesOnlyFromSendersOrMembers
        }
}

Export-Csv C:\Temp\DLs.csv

您尝试做的事情有点令人困惑,但看起来您正在尝试获取包含 100 个或更多成员的通讯组列表,然后将其导出到 csv。

我在您的代码中发现了一些问题。

  1. 您拨打 Get-DistributionGroup 的时间超出了您的需要。无需在循环内再次调用,只需使用您已有的 $dg 对象
  2. 类似的问题 'Get-DistributionGroupMember' 并计数。只需第一次存储对象,这样您就不必再次 运行 命令。
  3. 您没有向 Export-Csv
  4. 提供任何数据

修改后的代码

$distgroups = Get-DistributionGroup -ResultSize Unlimited
        
$distGroupsWith100PlusMembers = foreach ($dg in $distgroups) {
    # Store returned members in $members for later use
    if (($members = Get-DistributionGroupMember $dg.DistinguishedName).Count -ge 100) {
        # why are you getting ALL of the distribution groups again here?
        # Get-DistributionGroup -ResultSize Unlimited | 
        #    Select-Object DisplayName, ModerationEnabled, AcceptMessagesOnlyFromSendersOrMembers

        #use $dg instead
        $dg | Select-Object DisplayName, ModerationEnabled, AcceptMessagesOnlyFromSendersOrMembers
        Write-Host $dg.SamAccountName has $members.count members
    }
}

# Pipe the distribution groups (DisplayName, ModerationEnabled,
# AcceptMessagesOnlyFromSendersOrMembers) 
# found with 100 plus members to export-csv
$distGroupsWith100PlusMembers | Export-Csv C:\Temp\DLs.csv