forked from timmcmic/DLConversionV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset-Office365DL.ps1
280 lines (198 loc) · 12.9 KB
/
set-Office365DL.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<#
.SYNOPSIS
This function sets the single value attributes of the group created in Office 365.
.DESCRIPTION
This function sets the single value attributes of the group created in Office 365.
.PARAMETER originalDLConfiguration
The original configuration of the DL on premises.
.PARAMETER groupTypeOverride
Submits the group type override of specified by the administrator at run time.
.OUTPUTS
None
.EXAMPLE
set-Office365DL -originalDLConfiguration DLConfiguration -groupTypeOverride TYPEOVERRIDE.
#>
Function set-Office365DL
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$originalDLConfiguration,
[Parameter(Mandatory = $true)]
[string]$groupTypeOverride
)
#Declare function variables.
$functionModerationFlags=$NULL
$functionSendModerationNotifications=$NULL
$functionModerationEnabled=$NULL
$functionoofReplyToOriginator=$NULL
$functionreportToOwner=$NULL
$functionHiddenFromAddressList=$NULL
$functionMemberJoinRestriction=$NULL
$functionMemberDepartRestriction=$NULL
$functionRequireAuthToSendTo=$NULL
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN SET-Office365DL"
Out-LogFile -string "********************************************************************************"
#Log the parameters and variables for the function.
Out-LogFile -string ("OriginalDLConfiguration = ")
out-logfile -string $originalDLConfiguration
out-logfile -string ("Group Type Override = "+$groupTypeOverride)
#There are several flags of a DL that are either calculated hashes <or> booleans not set by default.
#The exchange commandlets abstract this by performing a conversion or filling the values in.
#Since we use ldap to get these values now - we must reverse engineer these and / or set them.
#If the group type was overridden from the default - the member join restriction has to be adjusted.
#If the group tyoe was not overriden - check to see if depart is NULL and set to closed which is default.
#Otherwise take the value from the string.
if ( $groupTypeOverride -eq "Security" )
{
out-logfile -string "Group type overriden to Security by administrator. This requires depart restriction closed."
$functionMemberDepartRestriction = "Closed"
out-logfile -string ("Function member depart restrictions = "+$functionMemberDepartRestriction)
}
elseif ($originalDLConfiguration.msExchGroupDepartRestriction -eq $NULL)
{
out-logFile -string ("Member depart restriction is NULL.")
$functionMemberDepartRestriction="Closed"
out-LogFile -string ("The member depart restriction is now = "+$functionMemberDepartRestriction)
}
elseif ($originalDLConfiguration.groupType -eq "-2147483640")
{
Out-logfile -string ("Group type is security - ensuring member depart restriction CLOSED")
$functionMemberDepartRestriction="Closed"
}
else
{
$functionMemberDepartRestriction = $originalDLConfiguration.msExchGroupDepartRestriction
out-logfile -string ("Function member depart restrictions = "+$functionMemberDepartRestriction)
}
#The moderation settings a are a hash valued flag.
#This test looks to see if bypass nested moderation is enabled from the hash.
if (($originalDLConfiguration.msExchModerationFlags -eq "1") -or ($originalDLConfiguration.msExchModerationFlags -eq "3") -or ($originalDLConfiguration.msExchModerationFlags -eq "7") )
{
out-logfile -string ("The moderation flags are 1 / 3 / 7 - setting bypass nested moderation to TRUE - "+$originalDLConfiguration.msExchModerationFlags)
$functionModerationFlags=$TRUE
out-logfile ("The function moderation flags are = "+$functionModerationFlags)
}
else
{
out-logfile -string ("The moderation flags are NOT 1 / 3 / 7 - setting bypass nested moderation to FALSE - "+$originalDLConfiguration.msExchModerationFlags)
$functionModerationFlags=$FALSE
out-logfile ("The function moderation flags is = "+$functionModerationFlags)
}
#Test now to see if the moderation settings are always, internal, or none. This uses the same hash.
if (($originalDLConfiguration.msExchModerationFlags -eq "0") -or ($originalDLConfiguration.msExchModerationFlags -eq "1") )
{
out-logfile -string ("The moderation flags are 0 / 2 / 6 - send notifications to never."+$originalDLConfiguration.msExchModerationFlags)
$functionSendModerationNotifications="Never"
out-logfile -string ("The function send moderations notifications is = "+$functionSendModerationNotifications)
}
elseif (($originalDLConfiguration.msExchModerationFlags -eq "2") -or ($originalDLConfiguration.msExchModerationFlags -eq "3") )
{
out-logfile -string ("The moderation flags are 0 / 2 / 6 - setting send notifications to internal."+$originalDLConfiguration.msExchModerationFlags)
$functionSendModerationNotifications="Internal"
out-logfile -string ("The function send moderations notifications is = "+$functionSendModerationNotifications)
}
elseif (($originalDLConfiguration.msExchModerationFlags -eq "6") -or ($originalDLConfiguration.msExchModerationFlags -eq "7") )
{
out-logfile -string ("The moderation flags are 0 / 2 / 6 - setting send notifications to always."+$originalDLConfiguration.msExchModerationFlags)
$functionSendModerationNotifications="Always"
out-logfile -string ("The function send moderations notifications is = "+$functionSendModerationNotifications)
}
else
{
out-logFile -string ("The moderation flags are not set. Setting to default of always.")
$functionSendModerationNotifications="Always"
out-logFile -string ("The function send moderation notification is = "+$functionSendModerationNotifications)
}
#Evaluate moderation enabled.
if ($originalDLConfiguration.msExchEnableModeration -eq $NULL)
{
out-logfile -string "The moderation enabled setting is null."
$functionModerationEnabled=$FALSE
out-logfile -string ("The updated moderation enabled flag is = "+$functionModerationEnabled)
}
else
{
out-logfile -string "The moderation setting was set on premises."
$functionModerationEnabled=$originalDLConfiguration.msExchEnableModeration
out-Logfile -string ("The function moderation setting is "+$functionModerationEnabled)
}
#Evaluate oofReplyToOriginator
if ($originalDLConfiguration.oofReplyToOriginator -eq $NULL)
{
out-logfile -string "The oofReplyToOriginator is null."
$functionoofReplyToOriginator = $FALSE
out-logfile -string ("The oofReplyToOriginator is now = "+$functionoofReplyToOriginator)
}
else
{
out-logFile -string "The oofReplyToOriginator was set on premises."
$functionoofReplyToOriginator=$originalDLConfiguration.oofReplyToOriginator
out-logfile -string ("The function oofReplyToOriginator = "+$functionoofReplyToOriginator)
}
#Evaluate reportToOwner
if ($originalDLConfiguration.reportToOwner -eq $NULL)
{
out-logfile -string "The reportToOwner is null."
$functionreportToOwner = $FALSE
out-logfile -string ("The reportToOwner is now = "+$functionreportToOwner)
}
else
{
out-logfile -string "The reportToOwner was set on premises."
$functionReportToOwner = $originalDLConfiguration.reportToOwner
out-logfile -string ("The function reportToOwner = "+$functionreportToOwner)
}
#Evaluate hidden from address list.
if ($originalDLConfiguration.msExchHideFromAddressLists -eq $NULL)
{
out-logfile -string ("Hidden from adddress list is null.")
$functionHiddenFromAddressList=$FALSE
out-logfile -string ("The hidden from address list is now = "+$functionHiddenFromAddressList)
}
else
{
out-logFile -string ("Hidden from address list is not null.")
$functionHiddenFromAddressList=$originalDLConfiguration.msExchHideFromAddressLists
}
#Evaluate member join restrictions.
if ($originalDLConfiguration.msExchGroupJoinRestriction -eq $NULL)
{
out-Logfile -string ("Member join restriction is NULL.")
$functionMemberJoinRestriction="Closed"
out-logfile -string ("The member join restriction is now = "+$functionMemberJoinRestriction)
}
else
{
$functionMemberJoinRestriction = $originalDLConfiguration.msExchGroupJoinRestriction
out-logfile -string ("The function member join restriction is: "+$functionMemberJoinRestriction)
}
#Evaluate require auth to send to DL. If the DL is open to everyone - the value may not be present.
if ($originalDLConfguration.msExchRequireAuthToSendTo -eq $NULL)
{
out-logfile -string ("Require auth to send to is not set.")
$functionRequireAuthToSendTo = $FALSE
out-logfile -string ("The new require auth to sent to is: "+$functionRequireAuthToSendTo)
}
else
{
out-logfile -string ("Require auth to send to is set - retaining value. "+ $originalDLConfguration.msExchRequireAuthToSendTo)
$functionRequireAuthToSendTo = $originalDLConfguration.msExchRequireAuthToSendTo
}
try
{
out-logfile -string "Setting the single value settings for the distribution group."
Set-O365DistributionGroup -Identity $originalDLConfiguration.mailNickName -BypassNestedModerationEnabled $functionModerationFlags -MemberJoinRestriction $functionMemberJoinRestriction -MemberDepartRestriction $functionMemberDepartRestriction -ReportToManagerEnabled $functionreportToOwner -ReportToOriginatorEnabled $originalDLConfiguration.reportToOriginator -SendOofMessageToOriginatorEnabled $functionoofReplyToOriginator -Alias $originalDLConfiguration.mailNickName -CustomAttribute1 $originalDLConfiguration.extensionAttribute1 -CustomAttribute10 $originalDLConfiguration.extensionAttribute10 -CustomAttribute11 $originalDLConfiguration.extensionAttribute11 -CustomAttribute12 $originalDLConfiguration.extensionAttribute12 -CustomAttribute13 $originalDLConfiguration.extensionAttribute13 -CustomAttribute14 $originalDLConfiguration.extensionAttribute14 -CustomAttribute15 $originalDLConfiguration.extensionAttribute15 -CustomAttribute2 $originalDLConfiguration.extensionAttribute2 -CustomAttribute3 $originalDLConfiguration.extensionAttribute3 -CustomAttribute4 $originalDLConfiguration.extensionAttribute4 -CustomAttribute5 $originalDLConfiguration.extensionAttribute5 -CustomAttribute6 $originalDLConfiguration.extensionAttribute6 -CustomAttribute7 $originalDLConfiguration.extensionAttribute7 -CustomAttribute8 $originalDLConfiguration.extensionAttribute8 -CustomAttribute9 $originalDLConfiguration.extensionAttribute9 -ExtensionCustomAttribute1 $originalDLConfiguration.msExtensionCustomAttribute1 -ExtensionCustomAttribute2 $originalDLConfiguration.msExtensionCustomAttribute2 -ExtensionCustomAttribute3 $originalDLConfiguration.msExtensionCustomAttribute3 -ExtensionCustomAttribute4 $originalDLConfiguration.msExtensionCustomAttribute4 -ExtensionCustomAttribute5 $originalDLConfiguration.msExtensionCustomAttribute5 -DisplayName $originalDLConfiguration.DisplayName -HiddenFromAddressListsEnabled $functionHiddenFromAddressList -ModerationEnabled $functionModerationEnabled -RequireSenderAuthenticationEnabled $functionRequireAuthToSendTo -SimpleDisplayName $originalDLConfiguration.DisplayNamePrintable -SendModerationNotifications $functionSendModerationNotifications -WindowsEmailAddress $originalDLConfiguration.mail -MailTipTranslations $originalDLConfiguration.msExchSenderHintTranslations -Name $originalDLConfiguration.cn -BypassSecurityGroupManagerCheck
}
catch
{
Out-LogFile -string $_ -isError:$TRUE
}
out-logfile -string "Sleeping 15 seconds to allow for Office 365 directory replication."
start-sleep -Seconds 15
Out-LogFile -string "END SET-Office365DL"
Out-LogFile -string "********************************************************************************"
}