Last active
February 5, 2019 19:34
-
-
Save poiriersimon/bb9531ea257c38dc9c81056ccf110e23 to your computer and use it in GitHub Desktop.
This script is used to get the list of all member of a Distribution list that contain other Distribution list, the result is a pure list of user or contact that are contain is those recursive Distribution List I found this useful to manage New-App Userlist with group ex : New-App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function Get-DistributionGroupExpandedMember { | |
Param( | |
[Parameter(Mandatory=$True,ValueFromPipeline=$True)][String] $Identity | |
) | |
BEGIN{ | |
} | |
PROCESS { | |
$ExpandedDLList = @() | |
[array]$DL = Get-DistributionGroupMember $Identity | |
$tempDLList = @() | |
[array]$tempDLList = Get-DistributionGroupMember $Identity | where {$_.RecipientType -ne "MailUniversalDistributionGroup" -and $_.RecipientType -ne "MailUniversalSecurityGroup"} | |
while(($DL | Where {$_.RecipientType -eq "MailUniversalDistributionGroup"}) -ne $NULL){ | |
foreach($item in ($DL | Where {$_.RecipientType -eq "MailUniversalDistributionGroup" -or $_.RecipientType -ne "MailUniversalSecurityGroup"})){ | |
$DLname = $item.name | |
$DLidentity = $item.identity | |
Write-Verbose "Checking $DLName" | |
if($ExpandedDLList -notcontains $DLidentity){ | |
Write-Verbose "Expanding $DLname" | |
$DL = $DL | where {$_.Name -ne $DLname} | |
$DL += Get-DistributionGroupMember $item.identity | |
[array]$tempDLList += Get-DistributionGroupMember $item.identity | where {$_.RecipientType -ne "MailUniversalDistributionGroup" -and $_.RecipientType -ne "MailUniversalSecurityGroup"} | |
}else{ | |
$DL = $DL | where {$_.Name -ne $DLname} | |
} | |
[Array]$ExpandedDLList += $DLidentity | |
} | |
} | |
} | |
END{ | |
return $tempDLList | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment