-
Notifications
You must be signed in to change notification settings - Fork 10
/
new-Office365DL.ps1
146 lines (108 loc) · 5.07 KB
/
new-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
<#
.SYNOPSIS
This function creates the new distribution group in office 365.
.DESCRIPTION
This function creates the new distribution group 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
new-Office365DL -groupTypeOverride "Security" -originalDLConfiguration adConfigVariable -office365DLConfiguration CONFIG
#>
Function new-office365dl
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
$originalDLConfiguration,
[Parameter(Mandatory = $true)]
$office365DLConfiguration,
[Parameter(Mandatory = $true)]
[string]$groupTypeOverride
)
#Output all parameters bound or unbound and their associated values.
write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)
#Declare function variables.
[string]$functionGroupType=$NULL #Holds the return information for the group query.
[string]$functionMailNickName = ""
[string]$functionName = ((Get-Date -Format FileDateTime)+(Get-Random)).tostring()
$functionDL = $NULL
$functionIsRoom = $FALSE
#Start function processing.
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN New-Office365DL"
Out-LogFile -string "********************************************************************************"
#Calculate the group type to be utilized.
#Three values - either NULL,Security,or Distribution.
out-Logfile -string ("The group type for evaluation is = "+$originalDLConfiguration.groupType)
if ($groupTypeOverride -Eq "Security")
{
out-logfile -string "The administrator overrode the group type to security."
$functionGroupType = "Security"
}
elseif ($groupTypeOverride -eq "Distribution")
{
out-logfile -string "The administrator overrode the group type to distribution."
$functionGroupType = "Distribution"
}
elseif ($groupTypeOverride -eq "None")
{
out-logfile -string "A group type override was not specified. Using group type from on premises."
if (($originalDLConfiguration.groupType -eq "-2147483640") -or ($originalDLConfiguration.groupType -eq "-2147483646") -or ($originalDLConfiguration.groupType -eq "-2147483644"))
{
out-logfile -string "The group type from on premises is security."
$functionGroupType = "Security"
}
elseif (($originalDLConfiguration.grouptype -eq "8") -or ($originalDLConfiguration.grouptype -eq "4") -or ($originalDLConfiguration.grouptype -eq "2"))
{
out-logfile -string "The group type from on premises is distribution."
$functionGroupType = "Distribution"
}
else
{
out-logfile -string "A group type override was not provided and the input did not include a valid on premises group type."
}
}
else
{
out-logfile -string "An invalid group type was utilized in function new-Office365DL" -isError:$TRUE
}
out-logfile -string ("Random DL name: "+$functionName)
#Test to determine if the distribution group is a room distribution group.
if ($originalDLConfiguration.msExchRecipientTypeDetails -eq "268435456")
{
out-logfile -string "The group is a room distribution list."
$functionIsRoom = $TRUE
}
else
{
out-logfile -string "The group is not a room distribution list."
}
#Create the distribution group in office 365.
try
{
if ($functionIsRoom -eq $FALSE)
{
out-logfile -string "Creating the distribution group in Office 365."
$functionDL = new-o365distributionGroup -name $functionName -type $functionGroupType -ignoreNamingPolicy:$TRUE -errorAction STOP
out-logfile -string $functionDL
}
else
{
out-logfile -string "Creating the distribution group in Office 365 as a room list."
$functionDL = new-o365distributionGroup -name $functionName -type $functionGroupType -ignoreNamingPolicy:$TRUE -roomList -errorAction STOP
out-logfile -string $functionDL
}
}
catch
{
Out-LogFile -string $_ -isError:$TRUE
}
Out-LogFile -string "END New-Office365DL"
Out-LogFile -string "********************************************************************************"
return $functionDL
}