-
Notifications
You must be signed in to change notification settings - Fork 0
/
start-replaceOffice365.ps1
155 lines (117 loc) · 6.32 KB
/
start-replaceOffice365.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
<#
.SYNOPSIS
This function begins the process of replacing the Office 365 settings for contacts that have been migrated that had cloud only dependencies.
.DESCRIPTION
This function begins the process of replacing the Office 365 settings for contacts that have been migrated that had cloud only dependencies.
.PARAMETER office365Attribute
The office 365 attribute.
.PARAMETER office365Member
The member that is being added.
.PARAMETER contactSMTPAddress
The member that is being added.
.OUTPUTS
None
.EXAMPLE
sstart-replaceOffice365 -office365Attribute Attribute -office365Member contactMember -contactSMTPAddress smtpAddess
#>
Function start-ReplaceOffice365
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$office365Attribute,
[Parameter(Mandatory = $true)]
$office365Member,
[Parameter(Mandatory = $true)]
[string]$contactSMTPAddress
)
[string]$isTestError="No"
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN start-ReplaceOffice365"
Out-LogFile -string "********************************************************************************"
#Log the parameters and variables for the function.
$functionCommand=$NULL
$functionMailboxRecipientType = "UserMailbox"
$functionDistributioncontactRecipientType = "MailUniversalDistributionGroup"
$functionSecuritycontactRecipientType = "MailUniversalSecurityGroup"
$functionMailUserRecipientType = "MailUser"
$functionMailContactRecipientType = "MailContact"
$functionUniveralRecipientDisplayType = "GroupMailbox"
$functionDynamicDistributioncontactRecipientType = "DynamicDistributionGroup"
$functionForwarding = "ForwardingAddress"
Out-LogFile -string ("Office 365 Attribute = "+$office365Attribute)
out-logfile -string ("Office 365 Member = "+$office365Member.primarySMTPAddress)
out-logfile -string ("Office 365 Recipient Type = "+$office365Member.recipientType)
out-logfile -string ("Office 365 Recipient Display Type Details ="+$office365Member.recipientTypeDetails)
#Declare function variables.
out-Logfile -string "Processing operation..."
if ($office365Attribute -eq $functionForwarding)
{
out-logfile -string "Recipient is a mailbox with forwarding rights."
$functionCommand="set-o365Mailbox -identity $office365Member -$office365Attribute '$contactSMTPAddress' -errorAction STOP"
out-logfile -string ("The command to execute: "+$functionCommand)
}
elseif (($office365Member.recipientType -eq $functionDistributioncontactRecipientType) -and ($office365Member.recipientTypeDetails -eq $functionUniveralRecipientDisplayType))
{
out-logfile -string "Recipient is a unified contact."
$functionCommand="set-o365UnifiedGroup -identity $office365Member -$office365Attribute @{add='$contactSMTPAddress'} -errorAction STOP"
out-logfile -string ("The command to execute: "+$functionCommand)
}
elseif (($office365Member.recipientType -eq $functionDistributioncontactRecipientType) -or ($office365Member.recipientType -eq $functionSecuritycontactRecipientType))
{
out-logfile -string "Recipient is a mail enabled distribution contact or mail enabled security contact."
$functionCommand="set-o365DistributionGroup -identity $office365Member -$office365Attribute @{add='$contactSMTPAddress'} -BypassSecurityGroupManagerCheck -errorAction STOP "
out-logfile -string ("The command to execute: "+$functionCommand)
}
elseif ($office365Member.recipientType -eq $functionDynamicDistributioncontactRecipientType)
{
out-logfile -string "Recipient is a dynamic distribution contact."
$functionCommand="set-o365DynamicDistributionGroup -identity $office365Member -$office365Attribute '$contactSMTPAddress' -errorAction STOP"
out-logfile -string ("The command to execute: "+$functionCommand)
}
elseif ($office365member.recipientType -eq $functionMailboxRecipientType)
{
out-logfile -string "Recipient is a mailbox."
$functionCommand="set-o365Mailbox -identity $office365Member -$office365Attribute @{add='$contactSMTPAddress'} -errorAction STOP"
out-logfile -string ("The command to execute: "+$functionCommand)
}
elseif ($office365Member.recipientType -eq $functionMailUserRecipientType)
{
out-logfile -string "Recipient is a mail user."
$functionCommand="set-o365MailUser -identity $office365Member -$office365Attribute @{add='$contactSMTPAddress'} -errorAction STOP"
out-logfile -string ("The command to execute: "+$functionCommand)
}
elseif ($office365Member.recipientType -eq $functionMailContactRecipientType)
{
out-logfile -string "Recipient is a mail user."
$functionCommand="set-o365MailContact -identity $office365Member -$office365Attribute @{add='$contactSMTPAddress'} -errorAction STOP"
out-logfile -string ("The command to execute: "+$functionCommand)
}
else
{
out-logfile "There is no acceptable recipient type specified. Manual intervention required."
$isTestError="Yes"
}
out-logfile -string "Recipient type is validated and correct command built."
if ($isTestError -ne "Yes")
{
$scriptBlock = [scriptBlock]::create($functionCommand)
out-logfile -string ("The script block to execute: "+$scriptBlock)
try {
& $scriptBlock
}
catch {
out-logfile -string $_
$isTestError="Yes"
}
}
else
{
out-logfile -string "Previous error encountered - no command executed."
}
Out-LogFile -string "END start-replaceOffice365"
Out-LogFile -string "********************************************************************************"
return $isTestError
}