-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path获取邮件组内成员信息.ps1
27 lines (25 loc) · 986 Bytes
/
获取邮件组内成员信息.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Set Variables:
$group = "[email protected]"
$members = New-Object System.Collections.ArrayList
$ScriptPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
## Create the Function
function getMembership($group) {
$searchGroup = Get-DistributionGroupMember $group -ResultSize Unlimited
foreach ($member in $searchGroup) {
if ($member.RecipientTypeDetails-match "Group" -and $member.Alias -ne "") {
getMembership($member.Alias)
}
else {
if ($member.Alias -ne "") {
if (! $members.Contains($member.Alias) ) {
$members.Add($member.Alias) >$null
}
}
}
}
}
## Run the function
getMembership($group)
## Output results to screen
Set-Location $ScriptPath
$members | Select @{N="UserName";E={$_}} | Export-Csv .\grouplist-rk-d.csv -NTI