-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalExchange-GetDistroGroups.ps1
48 lines (43 loc) · 2.3 KB
/
LocalExchange-GetDistroGroups.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# CSV file export path
$Csvfile = ".\ExportDGs.csv"
# Get all distribution groups
$Groups = Get-DistributionGroup -ResultSize Unlimited
# Loop through distribution groups
$Groups | ForEach-Object {
$GroupDN = $_.DistinguishedName
$DisplayName = $_.DisplayName
$PrimarySmtpAddress = $_.PrimarySmtpAddress
$SecondarySmtpAddress = $_.EmailAddresses | Where-Object {$_ -clike "smtp*"} | ForEach-Object {$_ -replace "smtp:",""}
$GroupType = $_.GroupType
$RecipientType = $_.RecipientType
$Members = Get-DistributionGroupMember $GroupDN -ResultSize Unlimited
$ManagedBy = $_.ManagedBy
$Alias = $_.Alias
$HiddenFromAddressLists = $_.HiddenFromAddressListsEnabled
$MemberJoinRestriction = $_.MemberJoinRestriction
$MemberDepartRestriction = $_.MemberDepartRestriction
$RequireSenderAuthenticationEnabled = $_.RequireSenderAuthenticationEnabled
$AcceptMessagesOnlyFrom = $_.AcceptMessagesOnlyFrom
$GrantSendOnBehalfTo = $_.GrantSendOnBehalfTo
$Notes = (Get-Group $GroupDN)
# Create objects
[PSCustomObject]@{
DisplayName = $DisplayName
PrimarySmtpAddress = $PrimarySmtpAddress
SecondaryStmpAddress = ($SecondarySmtpAddress -join ',')
Alias = $Alias
GroupType = $GroupType
RecipientType = $RecipientType
Members = ($Members.Name -join ',')
MembersPrimarySmtpAddress = ($Members.PrimarySmtpAddress -join ',')
ManagedBy = $ManagedBy.Name
HiddenFromAddressLists = $HiddenFromAddressLists
MemberJoinRestriction = $MemberJoinRestriction
MemberDepartRestriction = $MemberDepartRestriction
RequireSenderAuthenticationEnabled = $RequireSenderAuthenticationEnabled
AcceptMessagesOnlyFrom = ($AcceptMessagesOnlyFrom.Name -join ',')
GrantSendOnBehalfTo = $GrantSendOnBehalfTo.Name
Notes = $Notes.Notes
}
# Export report to CSV file
} | Sort-Object DisplayName | Export-CSV -Path $Csvfile -NoTypeInformation -Encoding UTF8 #-Delimiter ";"