I'm presently using the below script which exports each of my dynamic distribution group into a csv file for each list. I would like to modify the script, so instead of creating individual csv files for each dynamic distribution group, it populates the results into a single csv file that includes all the existing columns, but adding the name of the dynamic distribution group. I'm a powershell novice, so I would need the exact command provided I can just replace with my current one. Thanks in advance!
Write-Host "Getting all Dynamic Distribution Groups"
$DDLs = Get-DynamicDistributionGroup -ResultSize Unlimited
$primaryCounter = 0
Foreach ($DDL in $DDLs)
Write-Progress -Activity "Processing Groups" -Status "Current Group: $($DDL.Name) ($($primaryCounter)/$($DDLs.Count))" -Id 1 -PercentComplete (($primaryCounter/$DDLs.Count)*100)
$log = $DDL.Name + ".csv"
"Alias Company BusinessUnit Location Department DisplayName PrimarySmtpAddress RecipientType SamAccountName Title" | Out-File $log -Append
Write-Host "Finding all users that are currently members of $($DDL.Name)"
$members = Get-Recipient -RecipientPreviewFilter $DDL.RecipientFilter -ResultSize Unlimited
$subCounter = 0
foreach ($member in $members)
Write-Progress -Activity "Processing Group Members" -Status "$($member.alias) ($($subCounter)/$($members.count))" -Id 2 -ParentId 1 -PercentComplete (($subCounter/$members.count)*100)
$entry = $member.alias + " " + $member.company + " " + $member.customAttribute1 + " " + $member.customAttribute2 + " " + $member.department + " " + $member.DisplayName + " " + $member.PrimarySmtpAddress + " " + $member.recipientType + " " + $member.SamAccountName + " " + $member.title
$entry | Out-File $log -Append