I'm trying to export a csv full of Distribution Lists (from Exchange Online) above x members and with enabled moderation.
Problem here is that it's displaying ALL DL's with attributes I'm asking but completely ignoring the "above 100" part and without displaying the total count for each one.
The code I'm using is:
$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
Just for clarity, I've previously used this but with the same outcome:
$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
It's a little confusing what you are trying to do, but it looks like you are trying to get a list of distribution lists that have 100 or more members and then export that to csv.
There are a few issues that I can see in your code.
Get-DistributionGroup
more time than you need to. Instead of calling again inside the loop just use the$dg
object that you already haveExport-Csv
Revised Code