forked from timmcmic/DLConversionV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-replaceOffice365Dynamic.ps1
92 lines (64 loc) · 2.88 KB
/
start-replaceOffice365Dynamic.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
<#
.SYNOPSIS
This function begins the process of replacing the Office 365 settings for dynamic groups that have been migrated that had cloud only dependencies.
.DESCRIPTION
This function begins the process of replacing the Office 365 settings for dynamic groups that have been migrated that had cloud only dependencies.
.PARAMETER office365Attribute
The office 365 attribute.
.PARAMETER office365Member
The member that is being added.
.PARAMETER groupSMTPAddress
The member that is being added.
.OUTPUTS
None
.EXAMPLE
sstart-ReplaceOffice365Dynamic -office365Attribute Attribute -office365Member groupMember -groupSMTPAddress smtpAddess
#>
Function start-ReplaceOffice365Dynamic
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$office365Attribute,
[Parameter(Mandatory = $true)]
[string]$office365Member,
[Parameter(Mandatory = $true)]
[string]$groupSMTPAddress
)
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN start-ReplaceOffice365Dynamic"
Out-LogFile -string "********************************************************************************"
#Log the parameters and variables for the function.
$functionCommand=$NULL
Out-LogFile -string ("Office 365 Attribute = "+$office365Attribute)
out-logfile -string ("Office 365 Member = "+$office365Member.primarySMTPAddress)
#Declare function variables.
out-Logfile -string "Processing operation..."
if ($office365Attribute -eq "ManagedBy")
{
out-logfile -string "Attribute is managedBy - this is single value on Dynamic DLs"
$functionCommand="set-o365DynamicDistributionGroup -identity $office365Member -$office365Attribute '$groupSMTPAddress'"
out-logfile -string ("The command to execute: "+$functionCommand)
try{
invoke-expression -Command $functionCommand -errorAction Stop
}
catch{
out-logfile -string $_ -isError:$TRUE
}
}
else
{
$functionCommand="set-o365DynamicDistributionGroup -identity $office365Member -$office365Attribute @{add='$groupSMTPAddress'}"
out-logfile -string ("The command to execute: "+$functionCommand)
try{
invoke-expression -Command $functionCommand -errorAction Stop
}
catch{
out-logfile -string $_ -isError:$TRUE
}
}
Out-LogFile -string "END start-ReplaceOffice365Dynamic"
Out-LogFile -string "********************************************************************************"
}