-
-
Save azure365pro/2967bf30c676b568ed398acb7e3ffaa4 to your computer and use it in GitHub Desktop.
<# | |
.Requires -version 2 - Runs in Exchange Management Shell | |
.SYNOPSIS | |
.\DistributionGroupMemberReport.ps1 - It Can Display all the Distribution Group and its members on a List | |
Or It can Export to a CSV file | |
Example 1 | |
[PS] C:\DG>.\DistributionGroupMemberReport.ps1 | |
Distribution Group Member Report | |
---------------------------- | |
1.Display in Shell | |
2.Export to CSV File | |
Choose The Task: 1 | |
DisplayName Alias Primary SMTP address Distriubtion Group | |
----------- ----- -------------------- ------------------ | |
Atlast1 Atlast1 [email protected] Test1 | |
Atlast2 Atlast2 [email protected] Test1 | |
Blink Blink [email protected] Test1 | |
blink1 blink1 [email protected] Test1 | |
User2 User2 [email protected] Test11 | |
User3 User3 [email protected] Test11 | |
User4 User4 [email protected] Test11 | |
WithClient WithClient [email protected] Test11 | |
Blink Blink [email protected] Test11 | |
blink1 blink1 [email protected] Test11 | |
Example 2 | |
[PS] C:\DG>.\DistributionGroupMemberReport.ps1 | |
Distribution Group Member Report | |
---------------------------- | |
1.Display in Shell | |
2.Export to CSV File | |
Choose The Task: 2 | |
Enter the Path of CSV file (Eg. C:\DG.csv): C:\DGmembers.csv | |
.Author | |
Written By: Satheshwaran Manoharan | |
Change Log | |
V1.0, 11/10/2012 - Initial version | |
Change Log | |
V1.1, 02/07/2014 - Added "Enter the Distribution Group name with Wild Card" | |
Change Log | |
V1.2, 19/07/2014 - Added "Recipient OU,Distribution Group Primary SMTP address,Distribution Group Managers,Distribution Group OU" | |
V1.2.1, 19/07/2014 - Added "Option- Enter the Distribution Group name with Wild Card (Display)" | |
V1.2.2, 19/07/2014 - Added "Fixed "Hashtable-to-Object conversion is not supported in restricted language mode or a Data section" | |
V1.3,05/08/2014 - Hashtable-to-Object conversion is not supported - Fixed | |
V1.4,30/08/2015 - | |
Removed For loops - As its not listing distribution groups which has one member. | |
Added Value for Empty groups. It will list empty groups now as well. | |
V1.5,09/09/2015 - Progress Bars while exporting to CSV | |
V1.6,08/06/2019 - Added Encoding UTF-8 - Add Column Not allowed from Internet | |
V1.7,14/08/2019 - Added Column Distribution Group Managers Primary SMTP address | |
V1.8,12/01/2021 - Added Unified Group Member Report (Connect-ExchangeOnline) | |
#> | |
Write-host " | |
Distribution Group Member Report | |
---------------------------- | |
1. Display in Exchange Management Shell | |
2. Export to CSV File | |
3. Enter the Distribution Group name with Wild Card (Export) | |
4. Enter the Distribution Group name with Wild Card (Display) | |
Dynamic Distribution Group Member Report | |
---------------------------- | |
5. Display in Exchange Management Shell | |
6. Export to CSV File | |
7. Enter the Dynamic Distribution Group name with Wild Card (Export) | |
8. Enter the Dynamic Group name with Wild Card (Display) | |
Unified Group Member Report (Connect-ExchangeOnline) | |
---------------------------- | |
9. Display in Exchange Management Shell | |
10. Export to CSV File"-ForeGround "Cyan" | |
#---------------- | |
# Script | |
#---------------- | |
Write-Host " " | |
$number = Read-Host "Choose The Task" | |
$output = @() | |
switch ($number) | |
{ | |
1 { | |
$AllDG = Get-DistributionGroup -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $member.Alias | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
} | |
} | |
;Break} | |
2 { | |
$i = 0 | |
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DG.csv)" | |
$AllDG = Get-DistributionGroup -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $Member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $Member.Alias | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $Member.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $Member.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $Member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
} | |
# update counters and write progress | |
$i++ | |
Write-Progress -activity "Scanning Groups . . ." -status "Scanned: $i of $($allDg.Count)" -percentComplete (($i / $allDg.Count) * 100) | |
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8 | |
} | |
;Break} | |
3 { | |
$i = 0 | |
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DG.csv)" | |
$Dgname = Read-Host "Enter the DG name or Range (Eg. DGname , DG*,*DG)" | |
$AllDG = Get-DistributionGroup $Dgname -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $Member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $Member.Alias | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $Member.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $Member.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $Member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.GroupType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
} | |
# update counters and write progress | |
$i++ | |
Write-Progress -activity "Scanning Groups . . ." -status "Scanned: $i of $($allDg.Count)" -percentComplete (($i / $allDg.Count) * 100) | |
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8 | |
} | |
;Break} | |
4 { | |
$Dgname = Read-Host "Enter the DG name or Range (Eg. DGname , DG*,*DG)" | |
$AllDG = Get-DistributionGroup $Dgname -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-DistributionGroupMember $Dg.name -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $member.Alias | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
} | |
} | |
;Break} | |
5 { | |
$AllDG = Get-DynamicDistributionGroup -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $member.Alias | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
} | |
} | |
;Break} | |
6 { | |
$i = 0 | |
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DYDG.csv)" | |
$AllDG = Get-DynamicDistributionGroup -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $Member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $Member.Alias | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $Member.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $Member.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $Member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
} | |
# update counters and write progress | |
$i++ | |
Write-Progress -activity "Scanning Groups . . ." -status "Scanned: $i of $($allDg.Count)" -percentComplete (($i / $allDg.Count) * 100) | |
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8 | |
} | |
;Break} | |
7 { | |
$i = 0 | |
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\DYDG.csv)" | |
$Dgname = Read-Host "Enter the DG name or Range (Eg. DynmicDGname , Dy*,*Dy)" | |
$AllDG = Get-DynamicDistributionGroup $Dgname -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$managers = $Dg | Select @{Name='DistributionGroupManagers';Expression={[string]::join(";", ($_.Managedby))}} | |
$manageremail = Get-Mailbox $managers.DistributionGroupManagers -ErrorAction SilentlyContinue -resultsize unlimited | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $Member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $Member.Alias | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $Member.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $Member.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $Member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Primary SMTP address" -Value $DG.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers" -Value $managers.DistributionGroupManagers | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Managers Primary SMTP address" -Value $manageremail.primarysmtpaddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group OU" -Value $DG.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Distribution Group Recipient Type" -Value $DG.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $DG.RequireSenderAuthenticationEnabled | |
$output += $UserObj | |
} | |
} | |
# update counters and write progress | |
$i++ | |
Write-Progress -activity "Scanning Groups . . ." -status "Scanned: $i of $($allDg.Count)" -percentComplete (($i / $allDg.Count) * 100) | |
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8 | |
} | |
;Break} | |
8 { | |
$Dgname = Read-Host "Enter the Dynamic DG name or Range (Eg. DynamicDGname , DG*,*DG)" | |
$AllDG = Get-DynamicDistributionGroup $Dgname -resultsize unlimited | |
Foreach($dg in $allDg) | |
{ | |
$Members = Get-Recipient -RecipientPreviewFilter $dg.RecipientFilter -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $member.Alias | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Distribution Group" -Value $DG.Name | |
Write-Output $Userobj | |
} | |
} | |
} | |
;Break} | |
9 { | |
$AllUG = Get-UnifiedGroup -resultsize unlimited | |
Foreach($ug in $allug) | |
{ | |
$Members = Get-UnifiedGroupLinks $ug.name -LinkType member -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmtpyGroup | |
$userObj | Add-Member NoteProperty -Name "UnifiedGroup" -Value $ug.Name | |
Write-Output $Userobj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $member.Alias | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "UnifiedGroup" -Value $ug.Name | |
Write-Output $Userobj | |
} | |
} | |
} | |
;Break} | |
10 { | |
$i = 0 | |
$CSVfile = Read-Host "Enter the Path of CSV file (Eg. C:\UG.csv)" | |
$Allug = Get-UnifiedGroup -resultsize unlimited | |
Foreach($ug in $allug) | |
{ | |
$Members = Get-UnifiedGroupLinks $ug.name -LinkType member -resultsize unlimited | |
if($members.count -eq 0) | |
{ | |
$managers = $ug.managedby -join ',' | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value EmptyGroup | |
$userObj | Add-Member NoteProperty -Name "Unified Group" -Value $ug.Name | |
$userObj | Add-Member NoteProperty -Name "Unified Group Primary SMTP address" -Value $ug.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Unified Group Managers" -Value $managers | |
$userObj | Add-Member NoteProperty -Name "Unified Group OU" -Value $ug.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Unified Group Type" -Value $ug.GroupType | |
$userObj | Add-Member NoteProperty -Name "Unified Group Recipient Type" -Value $ug.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Unified Group Display Name" -Value $ug.DisplayName | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $ug.RequireSenderAuthenticationEnabled | |
$userObj | Add-Member NoteProperty -Name "Unified Group Access Type" -Value $ug.AccessType | |
$output += $UserObj | |
} | |
else | |
{ | |
Foreach($Member in $members) | |
{ | |
$managers = $ug.managedby -join ',' | |
$userObj = New-Object PSObject | |
$userObj | Add-Member NoteProperty -Name "DisplayName" -Value $Member.Name | |
$userObj | Add-Member NoteProperty -Name "Alias" -Value $Member.Alias | |
$userObj | Add-Member NoteProperty -Name "RecipientType" -Value $Member.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Recipient OU" -Value $Member.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Primary SMTP address" -Value $Member.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Unified Group" -Value $ug.Name | |
$userObj | Add-Member NoteProperty -Name "Unified Group Primary SMTP address" -Value $ug.PrimarySmtpAddress | |
$userObj | Add-Member NoteProperty -Name "Unified Group Managers" -Value $managers | |
$userObj | Add-Member NoteProperty -Name "Unified Group OU" -Value $ug.OrganizationalUnit | |
$userObj | Add-Member NoteProperty -Name "Unified Group Group Type" -Value $ug.GroupType | |
$userObj | Add-Member NoteProperty -Name "Unified Group Recipient Type" -Value $ug.RecipientType | |
$userObj | Add-Member NoteProperty -Name "Unified Group Display Name" -Value $ug.DisplayName | |
$userObj | Add-Member NoteProperty -Name "Not Allowed from Internet" -Value $ug.RequireSenderAuthenticationEnabled | |
$userObj | Add-Member NoteProperty -Name "Unified Group Access Type" -Value $ug.AccessType | |
$output += $UserObj | |
} | |
} | |
# update counters and write progress | |
$i++ | |
Write-Progress -activity "Scanning Unified Groups . . ." -status "Scanned: $i of $($allug.Count)" -percentComplete (($i / $allug.Count) * 100) | |
$output | Export-csv -Path $CSVfile -NoTypeInformation -Encoding UTF8 | |
} | |
;Break} | |
Default {Write-Host "No matches found , Enter Options 1 or 2" -ForeGround "red"} | |
} |
Nice script. I would like to request modification to pull Office 365 type groups. The script ran fine against our tenant but misses all Microsoft 365 group types. Please email me if you can complete this change [email protected]
Thank you in advance!
Bobby
Added Unified Group Member Report (Connect-ExchangeOnline)
Nice script. I would like to request modification to pull Office 365 type groups. The script ran fine against our tenant but misses all Microsoft 365 group types. Please email me if you can complete this change [email protected]
Thank you in advance!
Bobby
Great. Thank you. You can send your contribution to [email protected]
Or
You can contribute directly on our public repo.
https://github.com/azure365pro/DistributionGroupMemberReport
Great work Guys 👍
Hi , I ran the script but it prompt me this while when i try using choice 4, it is ok to display. IS there any problem at my end ?! Appreciate your help! Thanks !
Attempted to divide by zero.
At C:\MyProgram\Powershell\DistributionGroupMemberReport.ps1:297 char:76
- ... Scanning Groups . . ." -status "Scanned:
$i of $ ($allDg.Count)" -perc ... -
~~~~~~~~~~~~
- CategoryInfo : NotSpecified: (:) [], RuntimeException
- FullyQualifiedErrorId : RuntimeException
Ihave a quick workaround, remark line #297 to do it and it works.
Hello. I have an issue with your nice script. For some reason when I use the script to print the results out to csv for distibution list the I get the value of "System.Collections.ArrayList" instead of the lists manager. No errors or anything while running this script. Can you please say what am I doing wrong?