SNSConfiguration.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
class SNSConfiguration
{
    [string]$LogFilePath='scoutnetSync.log'
    [string]$SyncGroupName='scoutnet'
    [string]$SyncGroupDescription="Säkerhetsgrupp som används vid synkronisering med Scoutnet. Användare i gruppen avaktiveras om de inte är kvar i Scoutnet."
    [string]$SyncGroupDisabledUsersName='scoutnetDisabledUsers'
    [string]$SyncGroupDisabledUsersDescription="Säkerhetsgrupp som används vid synkronisering med Scoutnet. Användare i gruppen är avaktiverade och finns inte längre med i Scoutnet."
    [string]$AllUsersGroupName=""
    hidden [System.Collections.Hashtable]$LicenseAssignment
    [string]$PreferredLanguage="sv-SE"
    [string]$UsageLocation="SE"
    [string]$WaitMailboxCreationMaxTime="1200"
    [string]$WaitMailboxCreationPollTime="30"
    [string]$SignatureText=""
    [string]$SignatureHtml=""
    [string]$NewUserEmailSubject=""
    [string]$NewUserEmailText=""
    [string]$NewUserEmailContentType="Text"
    [string]$NewUserInfoEmailSubject=""
    [string]$NewUserInfoEmailText=""
    [string]$NewUserInfoEmailContentType="Text"
    [string]$EmailFromAddress = ""
    [string]$UserSyncMailListId
    [pscredential]$CredentialCustomlists
    [pscredential]$CredentialMemberlist
    [System.Collections.Hashtable]$MailListSettings
    [string]$DomainName
    [string]$DisabledAccountsAutoReplyText
    [System.Collections.Hashtable]$ApiGroupMemberlistCache
    hidden [String]$commandNames
    hidden [String[]]$RequiredScopes = @("Directory.AccessAsUser.All",
    "Directory.ReadWrite.All",
    "Directory.Read.All",
    "GroupMember.Read.All",
    "GroupMember.ReadWrite.All",
    "Group.ReadWrite.All",
    "Group.Read.All",
    "User.ReadWrite.All",
    "User.Read.All",
    "Mail.Send")
}

function New-SNSConfiguration
{
    <#
    .SYNOPSIS
        Creates a new configuration.

    .INPUTS
        None. You cannot pipe objects to Get-SNSConfiguration.

    .OUTPUTS
        The created configuration

    .PARAMETER CredentialMemberlist
        Credentials for api/group/memberlist

    .PARAMETER CredentialCustomlists
        Credentials for api/group/customlists

    .PARAMETER MailListSettings
        Maillists to process for maillist syncronisation. A hashtable with maillist info.

    .PARAMETER DomainName
        Domain name for office365 mail addresses.

    .PARAMETER LicenseAssignment
        License assignment data to use when creating a new account.

    .PARAMETER UserSyncMailListId
        List Id to use when syncronising user accounts. If it is empty (default value) then all members with a role will be given an account.

    .PARAMETER LogFilePath
        Logfile name and path. Used to override the default value.

    .PARAMETER AllUsersGroupName
        Name of distribution group to add all new accounts to. The distribution group must exist.

    .PARAMETER SignatureText
        Outlook online signature for new users. Text version.

    .PARAMETER SignatureHtml
        Outlook online signature for new users. Html version.

    .PARAMETER NewUserEmailSubject
        Subject for the mail to the user about the new account. Is sent to the member Scoutnet primary e-mail address.

    .PARAMETER NewUserEmailText
        Body for the mail to the user about the new account. Is sent to the member Scoutnet primary e-mail address.

    .PARAMETER NewUserEmailContentType
        Content type for the email, supported types is HTML and Text. Default is Text.

    .PARAMETER NewUserInfoEmailSubject
        Subject for the mail to the users new e-mail address. Can be used to inform the user about the system.

    .PARAMETER NewUserInfoEmailText
        Body for the mail to the users new e-mail address. Can be used to inform the user about the system.

    .PARAMETER NewUserInfoEmailContentType
        Content type for the email, supported types is HTML and Text. Default is Text.

    .PARAMETER EmailFromAddress
        From address for all mails. The authenticaion account must be able to send as this address.

    .PARAMETER DisabledAccountsAutoReplyText
        Autoreply message for disabled accounts.
        If set this text is set as autoreply message for disabled accounts. Html is supported.
    #>

    [OutputType([SNSConfiguration])]
    param
    (
        [Parameter(HelpMessage="Credentials for api/group/memberlist.")]
        [pscredential]$CredentialMemberlist,

        [Parameter(HelpMessage="Credentials for api/group/customlist.")]
        [pscredential]$CredentialCustomlists,

        [Parameter(HelpMessage="Maillists to process.")]
        $MailListSettings,

        [Parameter(HelpMessage="Domain name for office365 mail addresses.")]
        [string]$DomainName,

        [Parameter(Mandatory=$true, HelpMessage="License data.")]
        [ValidateNotNull()]
        $LicenseAssignment,

        [Parameter(HelpMessage="List Id to use when syncronising user accounts.")]
        $UserSyncMailListId,

        [Parameter(HelpMessage="Logfile name and path.")]
        [string]$LogFilePath,

        [Parameter(HelpMessage="Name of distribution group to add all new accounts to.")]
        [string]$AllUsersGroupName,

        [Parameter(HelpMessage="Outlook online signature for new users. Text version.")]
        [string]$SignatureText,

        [Parameter(HelpMessage="Outlook online signature for new users. Html version.")]
        [string]$SignatureHtml,

        [Parameter(HelpMessage="Subject for the mail to the user about the new account.")]
        [string]$NewUserEmailSubject,

        [Parameter(HelpMessage="Body for the mail to the user about the new account.")]
        [string]$NewUserEmailText,

        [Parameter(HelpMessage="Content type for the email, supported types is Html and Text. Default is Text.")]
        [string]$NewUserEmailContentType,

        [Parameter(HelpMessage="Subject for the mail to the users new e-mail address.")]
        [string]$NewUserInfoEmailSubject,

        [Parameter(HelpMessage="Body for the mail to the users new e-mail address.")]
        [string]$NewUserInfoEmailText,

        [Parameter(HelpMessage="Content type for the email, supported types is Html and Text. Default is Text.")]
        [string]$NewUserInfoEmailContentType,

        [Parameter(HelpMessage="Autoreply message for disabled accounts.")]
        [string]$DisabledAccountsAutoReplyText
    )

    $conf = [SNSConfiguration]::new()

    if ($MailListSettings)
    {
        $conf.MailListSettings = $MailListSettings
    }

    if ($NewUserInfoEmailText)
    {
        $conf.NewUserInfoEmailText = $NewUserInfoEmailText
    }

    if ($NewUserInfoEmailContentType)
    {
        $conf.NewUserInfoEmailContentType = $NewUserInfoEmailContentType
    }

    if ($NewUserInfoEmailSubject)
    {
        $conf.NewUserInfoEmailSubject = $NewUserInfoEmailSubject
    }

    if ($NewUserEmailText)
    {
        $conf.NewUserEmailText = $NewUserEmailText
    }

    if ($NewUserEmailContentType)
    {
        $conf.NewUserEmailContentType = $NewUserEmailContentType
    }

    if ($NewUserEmailSubject)
    {
        $conf.NewUserEmailSubject = $NewUserEmailSubject
    }

    if ($SignatureHtml)
    {
        $conf.SignatureHtml = $SignatureHtml
    }

    if ($SignatureText)
    {
        $conf.SignatureText = $SignatureText
    }

    if ($AllUsersGroupName)
    {
        $conf.AllUsersGroupName = $AllUsersGroupName
    }

    if ($LogFilePath)
    {
        $conf.LogFilePath = $LogFilePath
    }

    if ($CredentialMemberlist)
    {
        $conf.CredentialMemberlist = $CredentialMemberlist
    }

    if ($CredentialCustomlists)
    {
        $conf.CredentialCustomlists = $CredentialCustomlists
    }

    if ($DomainName)
    {
        $conf.DomainName = $DomainName
    }

    if ($UserSyncMailListId)
    {
        $conf.UserSyncMailListId = $UserSyncMailListId
    }

    if ($DisabledAccountsAutoReplyText)
    {
        $conf.DisabledAccountsAutoReplyText = $DisabledAccountsAutoReplyText
    }

    if ($LicenseAssignment)
    {
        $conf.LicenseAssignment = $LicenseAssignment
    }

    # Exchange online commands to use.
    $conf.commandNames = "Get-EXOMailbox,Get-EXORecipient,"
    $conf.commandNames += "Get-DistributionGroupMember,Get-DistributionGroup,"
    $conf.commandNames += "Update-DistributionGroupMember,New-MailContact,"
    $conf.commandNames += "Set-Contact,Set-MailContact,Remove-MailContact,"
    $conf.commandNames += "Set-MailContact,Set-Mailbox,Remove-DistributionGroupMember,"
    $conf.commandNames += "Add-DistributionGroupMember,Get-DistributionGroupMember,"
    $conf.commandNames += "Get-DistributionGroup,Set-MailboxMessageConfiguration,"
    $conf.commandNames += "Set-MailboxAutoReplyConfiguration"

    return $conf
}

function Get-SNSConfiguration
{
    <#
    .SYNOPSIS
        Fetch current configuration.

    .INPUTS
        None. You cannot pipe objects to Get-SNSConfiguration.

    .OUTPUTS
        None.

    .PARAMETER new
        Create new empty configuration.
    #>

    [OutputType([SNSConfiguration])]
    param
    (
    )

    return $script:SNSConf
}

function Set-SNSConfiguration
{
    <#
    .SYNOPSIS
        Set a newconfiguration.

    .INPUTS
        None. You cannot pipe objects to Set-SNSConfiguration.

    .OUTPUTS
        None.

    .PARAMETER new
        Create new empty configuration.
    #>

    param
    (
        [Parameter(Mandatory=$True, HelpMessage="The new configuration.")]
        $Configuration
    )

    $script:SNSConf = $Configuration
}