-
Notifications
You must be signed in to change notification settings - Fork 0
/
set-Office365Contact.ps1
672 lines (555 loc) · 30.5 KB
/
set-Office365Contact.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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
<#
.SYNOPSIS
This function sets the single value attributes of the contact created in Office 365.
.DESCRIPTION
This function sets the single value attributes of the contact created in Office 365.
.PARAMETER originalContactConfiguration
The original configuration of the contact on premises.
.PARAMETER contactTypeOverride
Submits the contact type override of specified by the administrator at run time.
.OUTPUTS
None
.EXAMPLE
set-Office365contact -originalContactConfiguration contactConfiguration -contactTypeOverride TYPEOVERRIDE.
#>
Function set-Office365contact
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$originalContactConfiguration,
[Parameter(Mandatory = $true)]
$office365contactConfiguration,
[Parameter(Mandatory = $true)]
$office365contactConfigurationPostMigration,
[Parameter(Mandatory = $true)]
$manager
)
#Declare function variables.
$functionSendModerationNotifications=$NULL
$functionModerationEnabled=$NULL
$functionHiddenFromAddressList=$NULL
$functionRequireAuthToSendTo=$NULL
$functionMacFormat = ""
$functionMessageFormat = ""
$functionMessageBodyFormat = ""
$FunctionMapiRecipient=""
$functionUsePreferMessageFormat=""
[string]$functionMailNickName=""
[string]$functionDisplayName=""
[string]$functionSimpleDisplayName=""
[string]$functionWindowsEmailAddress=""
[boolean]$functionReportToOriginator=$NULL
[string]$functionExternalDirectoryObjectID = $office365contactConfigurationPostMigration.externalDirectoryObjectID
[boolean]$isTestError=$FALSE
[array]$functionErrors=@()
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN SET-Office365contact"
Out-LogFile -string "********************************************************************************"
#Log the parameters and variables for the function.
Out-LogFile -string ("originalContactConfiguration = ")
out-logfile -string $originalContactConfiguration
#There are several flags of a contact that are either calculated hashes <or> booleans not set by default.
#The exchange commancontactets 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.
#Test now to see if the moderation settings are always, internal, or none. This uses the same hash.
if (($originalContactConfiguration.msExchModerationFlags -eq "0") -or ($originalContactConfiguration.msExchModerationFlags -eq "1") )
{
out-logfile -string ("The moderation flags are 0 / 2 / 6 - send notifications to never."+$originalContactConfiguration.msExchModerationFlags)
$functionSendModerationNotifications="Never"
out-logfile -string ("The function send moderations notifications is = "+$functionSendModerationNotifications)
}
elseif (($originalContactConfiguration.msExchModerationFlags -eq "2") -or ($originalContactConfiguration.msExchModerationFlags -eq "3") )
{
out-logfile -string ("The moderation flags are 0 / 2 / 6 - setting send notifications to internal."+$originalContactConfiguration.msExchModerationFlags)
$functionSendModerationNotifications="Internal"
out-logfile -string ("The function send moderations notifications is = "+$functionSendModerationNotifications)
}
elseif (($originalContactConfiguration.msExchModerationFlags -eq "6") -or ($originalContactConfiguration.msExchModerationFlags -eq "7") )
{
out-logfile -string ("The moderation flags are 0 / 2 / 6 - setting send notifications to always."+$originalContactConfiguration.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 ($originalContactConfiguration.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=$originalContactConfiguration.msExchEnableModeration
out-Logfile -string ("The function moderation setting is "+$functionModerationEnabled)
}
#Evaluate hidden from address list.
if ($originalContactConfiguration.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=$originalContactConfiguration.msExchHideFromAddressLists
}
#Evaluate require auth to send to contact. If the contact is open to everyone - the value may not be present.
if ($originalContactConfiguration.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. "+ $originalContactConfiguration.msExchRequireAuthToSendTo)
$functionRequireAuthToSendTo = $originalContactConfiguration.msExchRequireAuthToSendTo
}
out-logfile -string "Determine mail contact internet coding."
if ($originalDLConfiguration.internetEncoding -eq "0")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Text"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 0"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "131072")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Text"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 131072"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "2097152")
{
$functionMacFormat = "uUEncode"
$functionMessageFormat = "Text"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 2097152"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "222824")
{
$functionMacFormat = "uUEncode"
$functionMessageFormat = "Text"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$true
out-logfile -string "Internet encoding value 222824"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "262144")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 262144"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "393216")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 393216"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "4456448")
{
$functionMacFormat = "AppleSingle"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 4456448"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "4587520")
{
$functionMacFormat = "AppleSingle"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$true
out-logfile -string "Internet encoding value 4587520"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "6553600")
{
$functionMacFormat = "AppleDouble"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 6553600"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "6684672")
{
$functionMacFormat = "AppleDouble"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "Text"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 6684672"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "786432")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "HTML"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 786432"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "917504")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "HTML"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 917504"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "7077888")
{
$functionMacFormat = "AppleDouble"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "HTML"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 7077888"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "7208960")
{
$functionMacFormat = "AppleDouble"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "HTML"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 7208960"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "4980736")
{
$functionMacFormat = "AppleSingle"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "HTML"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 4980736"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "5111808")
{
$functionMacFormat = "AppleSingle"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "HTML"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 5111808"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "5505024")
{
$functionMacFormat = "AppleSingle"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "TextandHTML"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 5505024"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "5636096")
{
$functionMacFormat = "AppleSingle"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "TextandHTML"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 5636096"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "7602176")
{
$functionMacFormat = "AppleDouble"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "TextAndHTML"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Internet encoding value 7602176"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "7733248")
{
$functionMacFormat = "AppleDouble"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "TextAndHTML"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Internet encoding value 7733248"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "1310720")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "TextandHTML"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Defaults intentionally set as value is present."
out-logfile -string "Internet encoding value 1310720"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
elseif ($originalDLConfiguration.internetEncoding -eq "1441792")
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "TextandHTML"
$functionUsePreferMessageFormat=$TRUE
out-logfile -string "Defaults intentionally set as value is present."
out-logfile -string "Internet encoding value 1441792"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
else
{
$functionMacFormat = "BinHex"
$functionMessageFormat = "Mime"
$functionMessageBodyFormat = "TextandHTML"
$functionUsePreferMessageFormat=$FALSE
out-logfile -string "Using default values as no explicit value was established on premises."
out-logfile -string "Internet encoding value 1310720"
out-logfile -string $functionMacFormat
out-logfile -string $functionMessageFormat
out-logfile -string $functionMessageBodyFormat
}
out-logfile -string "Evaluate if the object is a MAPI recipient."
if ($originalDLConfiguration.mapiRecipient -eq $NULL)
{
out-logfile -string "Mapi recipient is NULL = UseDefaultSettings"
$FunctionMapiRecipient="UseDefaultSettings"
}
elseif ($originalDLConfiguration.mapiRecipient -eq $TRUE)
{
out-logfile -string "Mapi Recipient is TRUE = Always"
$functionMapiRecipient="Always"
}
elseif ($originalDLConfiguration.mapiRecipient -eq $FALSE)
{
out-logfile -string "Mapi Recipient is FALSE = Never"
$functionMapiRecipient = "Never"
}
#It is possible that the contact is not fully mail enabled.
#contacts may now be represented as mail enabled if only MAIL is populated.
#If on premsies attributes are not specified - use the attributes that were obtained from office 365.
if ($originalContactConfiguration.mailNickName -eq $NULL)
{
out-logfile -string "On premsies contact does not have alias / mail nick name -> using Office 365 value."
$functionMailNickName = $office365contactConfiguration.alias
out-logfile -string ("Office 365 alias used for contact creation: "+$functionMailNickName)
}
else
{
out-logfile -string "On premises contact has a mail nickname specified - using on premsies value."
$functionMailNickName = $originalContactConfiguration.mailNickName
out-logfile -string $functionMailNickName
}
if ($originalContactConfiguration.displayName -ne $NULL)
{
$functionDisplayName = $originalContactConfiguration.displayName
}
else
{
$functionDisplayName = $office365contactConfiguration.displayName
}
if ($originalContactConfiguration.simpleDisplayNamePrintable -ne $NULL)
{
$functionSimpleDisplayName = $originalContactConfiguration.simpleDisplayNamePrintable
}
else
{
$functionSimpleDisplayName = $office365contactConfiguration.simpleDisplayName
}
try
{
out-logfile -string "Setting core single values for the contact contact."
set-o365MailContact -Identity $functionExternalDirectoryObjectID -name $originalContactConfiguration.cn -Alias $functionMailNickName -DisplayName $functionDisplayName -HiddenFromAddressListsEnabled $functionHiddenFromAddressList -RequireSenderAuthenticationEnabled $functionRequireAuthToSendTo -SimpleDisplayName $functionSimpleDisplayName -WindowsEmailAddress $originalContactConfiguration.mail -MailTipTranslations $originalContactConfiguration.msExchSenderHintTranslations -errorAction STOP
}
catch
{
out-logfile "Error encountered setting core single valued attributes."
out-logfile -string $_
$isErrorObject = new-Object psObject -property @{
PrimarySMTPAddressorUPN = $originalContactConfiguration.mail
ExternalDirectoryObjectID = $originalContactConfiguration.'msDS-ExternalDirectoryObjectId'
Alias = $functionMailNickName
Name = $originalContactConfiguration.name
Attribute = "Cloud contact list: Alias / DisplayName / HiddenFromAddressList / RequireSenderAuthenticaiton / SimpleDisplayName / WindowsEmailAddress / MailTipTranslations / Name"
ErrorMessage = "Error setting single valued attribute of the migrated contact list."
ErrorMessageDetail = $_
}
$functionErrors+=$isErrorObject
}
try
{
out-logfile -string "Setting single valued moderation propeties for the contact.."
set-o365MailContact -Identity $functionExternalDirectoryObjectID -ModerationEnabled $functionModerationEnabled -SendModerationNotifications $functionSendModerationNotifications -errorAction STOP
}
catch
{
out-logfile "Error encountered setting moderation properties of the contact...."
out-logfile -string $_
$isErrorObject = new-Object psObject -property @{
PrimarySMTPAddressorUPN = $originalContactConfiguration.mail
ExternalDirectoryObjectID = $originalContactConfiguration.'msDS-ExternalDirectoryObjectId'
Alias = $functionMailNickName
Name = $originalContactConfiguration.name
Attribute = "Cloud contact list: BypassNedstedModerationEnabled / ModerationEnabled / SendModerationNotifications"
ErrorMessage = "Error setting additional single valued attribute of the migrated contact contact."
ErrorMessageDetail = $_
}
$functionErrors+=$isErrorObject
}
try
{
out-logfile -string "Setting the custom and extension attributes of the contact."
set-o365MailContact -Identity $functionExternalDirectoryObjectID -CustomAttribute1 $originalContactConfiguration.extensionAttribute1 -CustomAttribute10 $originalContactConfiguration.extensionAttribute10 -CustomAttribute11 $originalContactConfiguration.extensionAttribute11 -CustomAttribute12 $originalContactConfiguration.extensionAttribute12 -CustomAttribute13 $originalContactConfiguration.extensionAttribute13 -CustomAttribute14 $originalContactConfiguration.extensionAttribute14 -CustomAttribute15 $originalContactConfiguration.extensionAttribute15 -CustomAttribute2 $originalContactConfiguration.extensionAttribute2 -CustomAttribute3 $originalContactConfiguration.extensionAttribute3 -CustomAttribute4 $originalContactConfiguration.extensionAttribute4 -CustomAttribute5 $originalContactConfiguration.extensionAttribute5 -CustomAttribute6 $originalContactConfiguration.extensionAttribute6 -CustomAttribute7 $originalContactConfiguration.extensionAttribute7 -CustomAttribute8 $originalContactConfiguration.extensionAttribute8 -CustomAttribute9 $originalContactConfiguration.extensionAttribute9 -ExtensionCustomAttribute1 $originalContactConfiguration.msExtensionCustomAttribute1 -ExtensionCustomAttribute2 $originalContactConfiguration.msExtensionCustomAttribute2 -ExtensionCustomAttribute3 $originalContactConfiguration.msExtensionCustomAttribute3 -ExtensionCustomAttribute4 $originalContactConfiguration.msExtensionCustomAttribute4 -ExtensionCustomAttribute5 $originalContactConfiguration.msExtensionCustomAttribute5 -errorAction STOP
}
catch
{
out-logfile "Error encountered setting custom and extension attributes of the contact...."
out-logfile -string $_
$isErrorObject = new-Object psObject -property @{
PrimarySMTPAddressorUPN = $originalContactConfiguration.mail
ExternalDirectoryObjectID = $originalContactConfiguration.'msDS-ExternalDirectoryObjectId'
Alias = $functionMailNickName
Name = $originalContactConfiguration.name
Attribute = "Cloud contact list: CustomAttributeX / ExtensionAttributeX"
ErrorMessage = "Error setting custom or extension attributes."
ErrorMessageDetail = $_
}
$functionErrors+=$isErrorObject
}
try
{
out-logfile -string "Setting internet encoding information."
set-o365MailContact -Identity $functionExternalDirectoryObjectID -macAttachmentFormat $functionMacFormat -messageFormat $functionMessageFormat -messageBodyFormat $functionMessageBodyFormat -usePreferMessageFormat $functionUsePreferMessageFormat -UseMapiRichTextFormat $functionMapiRecipient -errorAction STOP
}
catch
{
out-logfile "Error setting internet encoding settings....."
out-logfile -string $_
$isErrorObject = new-Object psObject -property @{
PrimarySMTPAddressorUPN = $originalContactConfiguration.mail
ExternalDirectoryObjectID = $originalContactConfiguration.'msDS-ExternalDirectoryObjectId'
Alias = $functionMailNickName
Name = $originalContactConfiguration.name
Attribute = "Cloud contact list: Internet encoding information / macFormat / messageFormat / MessageBodyFormat"
ErrorMessage = "Error setting custom or extension attributes."
ErrorMessageDetail = $_
}
$functionErrors+=$isErrorObject
}
try
{
out-logfile -string "Settings settings that can only be set with set-contact."
set-o365Contact -Identity $functionExternalDirectoryObjectID -notes $originalContactConfiguration.info -postalCode $originalContactConfiguration.postalCode -phone $originalContactConfiguration.telephoneNumber -office $originalContactConfiguration.physicalDeliveryOfficeName -countryOrRegion $originalContactConfiguration.c -otherTelephone $originalContactConfiguration.otherTelephone -pager $originalContactConfiguration.pager -fax $originalContactConfiguration.facsimileTelephoneNumber -postOfficeBox $originalContactConfiguration.postOfficeBox -company $originalContactConfiguration.company -city $originalContactConfiguration.L -title $originalContactConfiguration.title -MobilePhone $originalContactConfiguration.mobile -stateOrProvince $originalContactConfiguration.st -initials $originalContactConfiguration.initials -webPage $originalContactConfiguration.wwwHomePage -lastName $originalContactConfiguration.sn -HomePhone $originalContactConfiguration.homePhone -otherFax $originalContactConfiguration.otherFacsimileTelephoneNumber -department $originalContactConfiguration.department -otherHomePhone $originalContactConfiguration.otherHomePhone -FirstName $originalContactConfiguration.givenName -streetAddress $originalContactConfiguration.streetAddress
}
catch
{
out-logfile "Error setting internet encoding settings....."
out-logfile -string $_
$isErrorObject = new-Object psObject -property @{
PrimarySMTPAddressorUPN = $originalContactConfiguration.mail
ExternalDirectoryObjectID = $originalContactConfiguration.'msDS-ExternalDirectoryObjectId'
Alias = $functionMailNickName
Name = $originalContactConfiguration.name
Attribute = "Settings included in set-contact (not set-mailContact)"
ErrorMessage = "Error setting additonal properties of the contact."
ErrorMessageDetail = $_
}
$functionErrors+=$isErrorObject
}
if ($manager -ne "None")
{
out-logfile -string "Manager attribute is present."
try
{
out-logfile -string "Setting the manager on the mail contact.."
set-o365Contact -Identity $functionExternalDirectoryObjectID -manager $Manager.primarySMTPAddressOrUPN
}
catch
{
out-logfile "Error setting manager......"
out-logfile -string $_
$isErrorObject = new-Object psObject -property @{
PrimarySMTPAddressorUPN = $originalContactConfiguration.mail
ExternalDirectoryObjectID = $originalContactConfiguration.'msDS-ExternalDirectoryObjectId'
Alias = $functionMailNickName
Name = $originalContactConfiguration.name
Attribute = "Error setting manager."
ErrorMessage = "Manager was normalized, found in office 365, but attempts to set as manager were unsucessful. Manual add required."
ErrorMessageDetail = $_
}
$functionErrors+=$isErrorObject
}
}
else
{
out-logfile -string "There is no manager set."
}
Out-LogFile -string "END SET-Office365contact"
Out-LogFile -string "********************************************************************************"
out-logfile -string ("The number of function errors is: "+$functionerrors.count )
$global:postCreateErrors += $functionErrors
}